How to programmatically access the B4XCombox element whose constructor has the GradientDrawable property set?
I need this to change the view of a B4XCombox when it's not available.
No. There is no difference my friend. The problem with your background using code is you added a line that should not be there. See code below with the commented line:
B4X:
Sub setGradientDrawable(cmb As B4XComboBox,enable As Boolean)
Dim pnl As Panel = cmb.mBase
Dim gr As GradientDrawable
Dim cls(2) As Int
If enable Then
cls(0)=Colors.RGB(124,245,239)
cls(1)=Colors.RGB(13,142,137)
Else
cls(0)=Colors.LightGray
cls(1)=Colors.Gray
End If
' cls(0)=Colors.LightGray 'This line need to be commented or removed
gr.Initialize("TOP_BOTTOM",cls)
gr.CornerRadius=6dip
pnl.Background=gr
End Sub
Dim gr As GradientDrawable
Dim cls(2) As Int
cls(0)=Colors.LightGray
cls(1)=Colors.Green
gr.Initialize("TOP_BOTTOM",cls)
gr.CornerRadius=50dip
cmb.cmbBox.Background=gr
If the radius of curvature is set larger than set in the constructor, then the old fill is also visible.
Therefore, I am setting new values to another B4XComboBox element that is different from the constructor.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage") 'has your B4XCombobox2
Dim pnl As Panel = B4XComboBox2.mBase
pnl.Background = setGradientDrawable
End Sub
Sub setGradientDrawable As GradientDrawable
Dim gr As GradientDrawable
Dim cls(2) As Int
cls(0)=Colors.LightGray
cls(1)=Colors.Green
gr.Initialize("TOP_BOTTOM",cls)
gr.CornerRadius=50dip
Return gr
End Sub
Found another fact. The left ComboBox has properties set in the constructor, while the right one has properties set at runtime. The figure shows how the background color affects the right ComboBox.
I am attaching the project.
No. There is no difference my friend. The problem with your background using code is you added a line that should not be there. See code below with the commented line:
B4X:
Sub setGradientDrawable(cmb As B4XComboBox,enable As Boolean)
Dim pnl As Panel = cmb.mBase
Dim gr As GradientDrawable
Dim cls(2) As Int
If enable Then
cls(0)=Colors.RGB(124,245,239)
cls(1)=Colors.RGB(13,142,137)
Else
cls(0)=Colors.LightGray
cls(1)=Colors.Gray
End If
' cls(0)=Colors.LightGray 'This line need to be commented or removed
gr.Initialize("TOP_BOTTOM",cls)
gr.CornerRadius=6dip
pnl.Background=gr
End Sub