Android Question How to modify Drawable properies of a command button?

amorosik

Expert
Licensed User
1634263028373.png



How to change, via code, the 'Drawable' properties of a command button ?
For example, if I created the command button with the designer, and his name is cmdScelta1 and I wanted to change the 'Pressed Drawable / Color', how should I proceed?
 
Last edited:

amorosik

Expert
Licensed User
Thank you very much for the advice
Is the same valid even if the command button is a B4Xview?
I am asking this because I am attempting to change the properties as indicated on the link that Klaus posted
In my case the command button is a B4Xview
Above the code I'm testing
On the last line it tells me "Unknown member"
I would like to keep the B4Xview for reasons of compatibility with other environments, is it possible to obtain the same result with these as the classic buttons?

B4X:
' Define a color for Enabled state
Private cdwGreenColorEnabled As ColorDrawable
cdwGreenColorEnabled.Initialize(Colors.Green,10)

' Define a color for Pessed state
Private cdwGreenColorPressed As ColorDrawable
cdwGreenColorPressed.Initialize(Colors.RGB(255,182,18),10)

' Define a StateListDrawable
Private stdColor As StateListDrawable
stdColor.Initialize
stdColor.AddState(stdColor.State_Pressed, cdwGreenColorPressed)
stdColor.AddState(stdColor.State_Enabled, cdwGreenColorEnabled)
' Set StateListDrawable to button background

cmd1.Background = stdColor
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You cannot apply it directly to a B4XView.
You need to do it on the B4A button.
StateListDrawable is Android, therefor B4A specific.
You could do it like this:

B4X:
#If B4A
    Private cdwGreenColorEnabled As ColorDrawable
    cdwGreenColorEnabled.Initialize(Colors.Green,10)

    ' Define a color for Pessed state
    Private cdwGreenColorPressed As ColorDrawable
    cdwGreenColorPressed.Initialize(Colors.RGB(255,182,18),10)

    ' Define a StateListDrawable
    Private stdColor As StateListDrawable
    stdColor.Initialize
    stdColor.AddState(stdColor.State_Pressed, cdwGreenColorPressed)
    stdColor.AddState(stdColor.State_Enabled, cdwGreenColorEnabled)
    cmd.As(Button).Background = stdColor
#End If
 
Upvote 0
Top