Android Question can I change color of round button? [solved]

Hans- Joachim Krahe

Active Member
Licensed User
Longtime User
I need some round buttons, wich I created :

upload_2018-11-13_16-39-10.png


I can change color by disabeling, but need more minimum one more variation.

tried:

B4X:
 For Each v As View In Panel1.GetAllViewsRecursive
        If (GetType(V) = "android.widget.Button") Then
            Dim b As Button = v
            If b.Tag= "c1" Then
                b.Color= Colors.Green
            End If
        End If
  Next

but button became sqare while changing color.

other way could be to change into pressed status, but don't find a way to set it pressed by programm.
Would be happy for hints:))

setting the corner radius in programm could be solution. Does anyone know, how?
 
Last edited:

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Notice in your designer screenshot that the pressed/enabled/disabled are ColorDrawable, not Color. Create a new green colordrawable and assign it to the background property, rather than just setting the color of the button.
B4X:
 Dim poCD As ColorDrawable
 poCD.Initialize(Colors.Green, 110dip)
 b.Background = poCD
If you wish to set all of the states, you should use a StateListDrawable rather than a ColorDrawable.
 
Upvote 0

Hans- Joachim Krahe

Active Member
Licensed User
Longtime User
Notice in your designer screenshot that the pressed/enabled/disabled are ColorDrawable, not Color. Create a new green colordrawable and assign it to the background property, rather than just setting the color of the button.
B4X:
 Dim poCD As ColorDrawable
 poCD.Initialize(Colors.Green, 110dip)
 b.Background = poCD
If you wish to set all of the states, you should use a StateListDrawable rather than a ColorDrawable.

great. Works immidiately. many thanks
 
Upvote 0
Top