Android:以编程方式更改RadioButtons的颜色和复选框 [英] Android: Change the color of RadioButtons and checkboxes programmatically

查看:207
本文介绍了Android:以编程方式更改RadioButtons的颜色和复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 LinearLayout 中创建了 RadioButton CheckBox 。但是,现在我想更改单选按钮的颜色和复选框的颜色。我使用



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



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



但它没有工作。

解决方案

尝试此

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



<$ p $ 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);

这篇关于Android:以编程方式更改RadioButtons的颜色和复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆