SubName: SetColorStateList
Description:
Along with setting the background to buttons using a StateListDrawable, we can also change the color of the text (as with the default buttons) in a similar manner using a ColorStateList object.
This sub will set the Pressed, Enabled and Disabled text colors for a button. You can add more states if required, get the constant values from the StateListDrawable constants or from the documentation : http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html
You must provide as many colors as states.
Depends on: JavaObject
Tags: ColorStateList Button
Description:
Along with setting the background to buttons using a StateListDrawable, we can also change the color of the text (as with the default buttons) in a similar manner using a ColorStateList object.
This sub will set the Pressed, Enabled and Disabled text colors for a button. You can add more states if required, get the constant values from the StateListDrawable constants or from the documentation : http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html
You must provide as many colors as states.
Depends on: JavaObject
B4X:
'Pass the Button object and Colors int values to set for each state.
Sub SetColorStateList(Btn As Button,Pressed As Int,Enabled As Int,Disabled As Int)
Dim States(3,1) As Int
States(0,0) = 16842919 'Pressed
States(1,0) = 16842910 'Enabled
States(2,0) = -16842910 'Disabled
Dim Color(3) As Int = Array As Int(Pressed,Enabled,Disabled)
Dim CSL As JavaObject
CSL.InitializeNewInstance("android.content.res.ColorStateList",Array As Object(States,Color))
Dim B1 As JavaObject = Btn
B1.RunMethod("setTextColor",Array As Object(CSL))
End Sub
Tags: ColorStateList Button
Last edited: