The following code is taken from the Users Guide, to create a custom gradient on a panel. It works just like it is supposed to.
I want to use same concept to add custom gradient to a label. Only difference is I have added the label in designer rather than at run time. It does not work as expected, and I cannot figure out why. If I create the label at runtime, like the panel above, it works fine. Why does it work on label created at runtime but not on label created in Designer.
B4X:
Dim pnlGradient As Panel
pnlGradient.Initialize("")
Activity.AddView(pnlGradient, 10%x, 140dip, 80%x, 80dip)
Dim gdwGradient As GradientDrawable
Dim Cols(2) As Int
Cols(0) = Colors.Blue
Cols(1) = Colors.White
gdwGradient.Initialize("TOP_BOTTOM", Cols)
gdwGradient.CornerRadius = 10dip
pnlGradient.Background = gdwGradient
I want to use same concept to add custom gradient to a label. Only difference is I have added the label in designer rather than at run time. It does not work as expected, and I cannot figure out why. If I create the label at runtime, like the panel above, it works fine. Why does it work on label created at runtime but not on label created in Designer.
B4X:
''lblGradient is declared in Sub Globals
Dim gdwGradient As GradientDrawable
Dim Cols(2) As Int
Cols(0) = Colors.Blue
Cols(1) = Colors.White
gdwGradient.Initialize("TOP_BOTTOM", Cols)
gdwGradient.CornerRadius = 10dip
lblGradient.Background = gdwGradient