I tried to make one or another button change its colour using code. When the button click is fired, the corner radius is lost. How can I make the buttons not losing their rounded corners?
B4X:
#Region Project Attributes
#ApplicationLabel: Buttons
#VersionCode: 1
#VersionName:
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
Private btnOff As Button
Private btnOn As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnOn_Click
btnOn.Color = Colors.RGB(0, 255, 0)
btnOff.Color = Colors.RGB(105, 105, 105)
End Sub
Sub btnOff_Click
btnOn.Color = Colors.RGB(105, 105, 105)
btnOff.Color = Colors.RGB(255, 20, 147)
End Sub
Thanks @asales
The code works. I forgotten this method.
B4X:
Sub btnOn_Click
Dim cd1 As ColorDrawable
Dim cd2 As ColorDrawable
cd1.Initialize(Colors.RGB(0, 255, 0), 50dip)
cd2.Initialize(Colors.RGB(105, 105, 105), 50dip)
btnOn.Background = cd1
btnOff.Background = cd2
End Sub
Sub btnOff_Click
Dim cd1 As ColorDrawable
Dim cd2 As ColorDrawable
cd1.Initialize(Colors.RGB(105, 105, 105), 50dip)
cd2.Initialize(Colors.RGB(255, 20, 147), 50dip)
btnOn.Background = cd1
btnOff.Background = cd2
End Sub
1. It is simplest to change the colors with the designer
2. If you do it programmatically then it is better to use StateListDrawable with ColorDrawables.
1. It is simplest to change the colors with the designer
2. If you do it programmatically then it is better to use StateListDrawable with ColorDrawables.
I have used the StateListDrawable in designer but when I change the colour with code, the corner reset to 0.
The StateListDrawable only have Enabled, Disabled and Pressed Drawable. I want the button change colour.