且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android:以编程方式更改RadioButtons的颜色和复选框

更新时间:2023-10-06 21:10:52

尝试此

  AppCompatRadioButton newRadioButton = new AppCompatRadioButton(this); 
AppCompatCheckBox newCheckBox = new AppCompatCheckBox(this);



RadioGroup newRadioButton = new RadioGroup(this);
CheckBox newCheckBox = new CheckBox(this);


I created RadioButton and CheckBox in LinearLayout programatically. But, now I want to change radio button's color and check boxes's color. I use

RadioButton.setHighlightColor(Color.parseColor("#0c83bd"));

checkbox.setHighlightColor(Color.parseColor("#0c83bd"));

But it didn't work.

Try this

AppCompatRadioButton newRadioButton = new AppCompatRadioButton(this);
AppCompatCheckBox newCheckBox = new AppCompatCheckBox(this);

Insted of

RadioGroup newRadioButton = new RadioGroup(this);
CheckBox newCheckBox = new CheckBox(this);