我有一個有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。鑄造它的伎倆 –