我有一个有4个单选按钮的收音机组。我使用此代码:更改未识别的单选按钮的文字颜色
int radioButtonID = radioGroup.getCheckedRadioButtonId();
View checkedRadioButton = radioGroup.findViewById(radioButtonID);
int idx = radioGroup.indexOfChild(checkedRadioButton);
检索选中的单选按钮的索引。
问题是,我想改变选中的单选按钮的文本颜色,而我不知道每次具体的单选按钮。所以:checkedRadioButton.setTextColor(color);
让我发现,我需要“添加一个限定词”,这basicaly正显示出我,我应该使用一个特定的单选按钮来调用该方法,就像一个错误:
radioButtonAns1.setTextColor(color);
我想如果有人也会解释为什么我有这个错误,如果有解决方案。唯一可以调用的方法是.setBackgroundColor()
,看起来很丑。
在此先感谢!
RadioButton checkedRadioButton = (RadioButton) radioGroup.findViewById(radioButtonID);
checkedRadioButton.setTextColor(color);
的事情是,我尝试访问的单选按钮,而不是无线电集团。我只需要指定我想要返回一个RadioButton而不是一个View。铸造它的伎俩 –