Android 更改放射组圆颜色

Android 更改放射组圆颜色,android,Android,我有一个放射组,试图改变圆圈的颜色。我的代码如下所示,但在让“setButtonTintList”正常工作时遇到了问题 您的代码示例使用的是setButtonTextList而不是setbuttonintlist,但是仅更改它是没有帮助的setButtonTintList可以在RadioButton上调用,而不是在RadioGroup上调用。您可以使用getChildCount对您的总数和getChildAt(i)循环查看组中的按钮,以获取每个单选按钮,并在每个按钮上调用setButtonTin

我有一个放射组,试图改变圆圈的颜色。我的代码如下所示,但在让“setButtonTintList”正常工作时遇到了问题


您的代码示例使用的是
setButtonTextList
而不是
setbuttonintlist
,但是仅更改它是没有帮助的
setButtonTintList
可以在RadioButton上调用,而不是在RadioGroup上调用。您可以使用
getChildCount
对您的总数和
getChildAt(i)
循环查看组中的按钮,以获取每个单选按钮,并在每个按钮上调用
setButtonTintList

或者,如果xml文件中有单选按钮,则可以添加backgroundTint属性

android:backgroundTint="#000000"

注意:这些将不适用于API版本<21

您的代码示例使用的是
setButtonTextList
而不是
setButtonIntList
,但是仅更改它是没有帮助的
setButtonTintList
可以在RadioButton上调用,而不是在RadioGroup上调用。您可以使用
getChildCount
对您的总数和
getChildAt(i)
循环查看组中的按钮,以获取每个单选按钮,并在每个按钮上调用
setButtonTintList

或者,如果xml文件中有单选按钮,则可以添加backgroundTint属性

android:backgroundTint="#000000"

注意:这些不适用于API版本<21

正常。谢谢你的意见。我是通过以下方式实现的:

                int textColor = Color.parseColor("#000000");
                int count = radiogroup.getChildCount();
                for (int i=0;i<count;i++) {
                    RadioButton x = (RadioButton) radiogroup.getChildAt(i);
                    x.setButtonTintList(ColorStateList.valueOf(textColor));
int textColor=Color.parseColor(#000000”);
int count=radiogroup.getChildCount();

对于(int i=0;i好的。感谢您的输入。我使用了以下工具:

                int textColor = Color.parseColor("#000000");
                int count = radiogroup.getChildCount();
                for (int i=0;i<count;i++) {
                    RadioButton x = (RadioButton) radiogroup.getChildAt(i);
                    x.setButtonTintList(ColorStateList.valueOf(textColor));
int textColor=Color.parseColor(#000000”);
int count=radiogroup.getChildCount();

对于(int i=0;我可以发布更大的代码示例吗?您可以发布更大的代码示例吗?这是我目前拥有的:int textColor=Color.parseColor(“#000000”);int count=group.getChildCount();for(int i=0;i使用最新的代码,您看到了什么?它没有改变颜色,或者SetButtonIntList仍然无法调用?如果是后者,您可能需要将子对象强制转换为RadioButton,((RadioButton)group.getChildAt(i)).SetButtonIntList(ColorStateList.valueOf(textColor));是的,无法调用setButtonTintList。这是我当前拥有的:int textColor=Color.parseColor(“#000000”);int count=group.getChildCount();for(int i=0;i使用最新的代码,您看到了什么?它没有改变颜色,或者setButtonTintList仍然无法调用?如果是后者,您可能需要将子对象强制转换为RadioButton,((RadioButton)group.getChildAt(i)).setButtonTintList(ColorStateList.valueOf(textColor));是的,无法调用setButtonTintList。