如果在android中单击,则更改RadioButton的文本颜色

如果用户点击,我想更改单选按钮的文本颜色.但是我可以改变背景颜色,但我不想那样……任何人都可以告诉如何根据选择的正确或错误的选择放置十字或右标……?
这是我的主类代码..
final RadioButton Red = (RadioButton)findViewById(R.id.radioButton1);
    //RadioButton Blue = (RadioButton)findViewById(R.id.radioButton2);
    RadioButton Green = (RadioButton)findViewById(R.id.radioButton3);


    Red.setonCheckedchangelistener(new OnCheckedchangelistener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView,boolean      isChecked) {
        if(isChecked) {
            Red.setBackgroundColor(Color.RED);
        }

        }
    });
    Green.setonCheckedchangelistener(new OnCheckedchangelistener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
            // Todo Auto-generated method stub

        }
    });

这是我的布局文件

<RadioGroup
    android:id="@+id/radiogroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RadioButton" 
        />

    <RadioButton
        android:id="@+id/radioButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RadioButton" />

    <RadioButton
        android:id="@+id/radioButton3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RadioButton" />
</RadioGroup>

解决方法

要更改radiobutton的文本颜色
Red.setonCheckedchangelistener(new OnCheckedchangelistener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
        if (isChecked) {
            Red.setTextColor(Color.RED);
        }
    }
});

对于自定义图标;在drawable文件夹中创建一个radiobutton.xml,其中包含:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/checked_icon" android:state_checked="true"/>
    <item android:drawable="@drawable/unchecked_icon" android:state_checked="false"/>
</selector>

并将这些行放在styles.xml中(在您的values文件夹中):

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CustomTheme" parent="android:Theme">
        <item name="android:radioButtonStyle">@style/RadioButton</item>
    </style>
    <style name="RadioButton" parent="@android:style/Widget.CompoundButton.RadioButton">
        <item name="android:button">@drawable/radiobutton</item>
    </style>
</resources>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...