Android Question SetRadioButtonStatesColor

ArminKH

Well-Known Member
hi
why this code works
B4X:
Public Sub SetRadioButtonStatesColor(AppCompatRadioButton As ACRadioButton,CheckedColor As Int,EnabledColor As Int,DisabledColor As Int)
        Dim States(3,1) As Int
            States(0,0) = 16842912    'Checked
            States(1,0) = 16842910    'Enabled
            States(2,0) = -16842910   'Disabled

        Dim Color(3) As Int = Array As Int(CheckedColor,EnabledColor,DisabledColor)

        Dim CSL As JavaObject
            CSL.InitializeNewInstance("android.content.res.ColorStateList",Array As Object(States,Color))
        Dim CB1 As JavaObject = AppCompatRadioButton
            CB1.RunMethod("setSupportButtonTintList",Array As Object(CSL))

End Sub
but this one not works(for disabled state)
B4X:
    public void SetRadioButtonStatesColor(AppCompatRadioButton  AppCompatRadioButton,int CheckedColor,int EnabledColor,int DisabledColor){
        int[][] States = new int[3][1];
            States[0][0] =  16842912;    //Checked
            States[1][0] =  16842910;    //Enabled
            States[2][0] = -16842910;    //Disabled
       
        int[] Color = new int[3];
            Color[0] = CheckedColor;
            Color[1] = EnabledColor;
            Color[2] = DisabledColor;
       
        ColorStateList colorStateList = new ColorStateList(States,Color);        
        AppCompatRadioButton.setSupportButtonTintList(colorStateList);
    }
what is the problem? this code works for Checked and Enabled state but dont works for disabled state
same code works for ACCheckBox
@corwin42
 
Last edited:

msa

Member
Licensed User
Longtime User
check this :

B4X:
public void SetRadioButtonStatesColor(AppCompatRadioButton AppCompatRadioButton,int CheckedColor,int EnabledColor,int DisabledColor){

int[][] States = new int[3][];

States[0] = new int[]{16842912}; //Checked
States[1] = new int[]{16842910}; //Enabled
States[2] = new int[]{-16842910}; //Disabled

int[] Color = new int[3];
Color[0] = CheckedColor;
Color[1] = EnabledColor;
Color[2] = DisabledColor;

ColorStateList colorStateList = new ColorStateList(States,Color);
AppCompatRadioButton.setSupportButtonTintList(colorStateList);
}
 
Upvote 0

ArminKH

Well-Known Member
check this :

B4X:
public void SetRadioButtonStatesColor(AppCompatRadioButton AppCompatRadioButton,int CheckedColor,int EnabledColor,int DisabledColor){

int[][] States = new int[3][];

States[0] = new int[]{16842912}; //Checked
States[1] = new int[]{16842910}; //Enabled
States[2] = new int[]{-16842910}; //Disabled

int[] Color = new int[3];
Color[0] = CheckedColor;
Color[1] = EnabledColor;
Color[2] = DisabledColor;

ColorStateList colorStateList = new ColorStateList(States,Color);
AppCompatRadioButton.setSupportButtonTintList(colorStateList);
}
thank u it's works
as you have just 6 message since 2013 to now (2 message per year) so i'm so lucky :D
 
Upvote 0
Top