Android Question B4XCombox GradientDrawable property

Sergey_New

Well-Known Member
Licensed User
Longtime User
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.
 
Solution
the background color affects the right ComboBox
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
1690997911393.png

Sergey_New

Well-Known Member
Licensed User
Longtime User
I tried to do it like this:
B4X:
    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.
2.png

Therefore, I am setting new values to another B4XComboBox element that is different from the constructor. :(
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
If the radius of curvature is set larger than set in the constructor, then the old fill is also visible.
Use the Combo base panel:
B4X:
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
1690971962766.png
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Mahares, thank you!
It works.
Tell me, please, is there any label in the composition of the specified panel for assigning text to it?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
is there any label in the composition of the specified panel for assigning text to it?
As Erel answered, it is a panel with the old style spinner. Maybe something like this if I understand the question:
B4X:
Dim cs As CSBuilder
    cs.Initialize.Color(xui.Color_Red).Append("Moscow").PopAll
    B4XComboBox2.cmbBox.Addall(Array(cs))
Otherwise, wait for Erel to address it again
1690976888768.png
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
I checked your code in post #5 again and saw that I can't see the triangle as in the picture. What's the matter?
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
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.
3.png

I am attaching the project.
 

Attachments

  • temp.zip
    3.9 KB · Views: 49
Upvote 0

Mahares

Expert
Licensed User
Longtime User
the background color affects the right ComboBox
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
1690997911393.png
 
Upvote 0
Solution
Top