【发布时间】:2017-07-21 02:45:43
【问题描述】:
我有一个带有 4 个单选按钮的单选组。我使用此代码:
int radioButtonID = radioGroup.getCheckedRadioButtonId();
View checkedRadioButton = radioGroup.findViewById(radioButtonID);
int idx = radioGroup.indexOfChild(checkedRadioButton);
检索选中的单选按钮的索引。
问题是我想更改选中单选按钮的文本颜色,而我每次都不知道具体的单选按钮。所以:checkedRadioButton.setTextColor(color);
显示我需要“添加限定符”的错误,这基本上告诉我应该使用特定的单选按钮来调用该方法,例如:
radioButtonAns1.setTextColor(color);
我想是否有人也能解释我为什么会出现该错误以及是否有解决方案。我唯一可以调用的方法是.setBackgroundColor(),它看起来很丑。
提前致谢!
【问题讨论】:
标签: java android android-studio radio-button