改变圆形按钮- Android按钮的颜色

时间:2022-11-20 22:47:20

I want to change the color of circle of radio button,I could not understand which property to set.The background color I am having is black so it gets invisible.I want to set the color of circle to white.

我想改变单选按钮圆形的颜色,我不知道该设置哪个属性,我的背景色是黑色的,所以它是不可见的。我想把圆形的颜色设为白色。

16 个解决方案

#1


28  

This site is really good for customizing Android components in general: http://android-holo-colors.com/

这个网站非常适合定制Android组件:http://android-holo-colors.com/

Just choose the radio button, make the color white, download, and profit!

只要选择单选按钮,使颜色变白,下载,利润!

More Information

更多的信息

If after doing that you cannot see your requested change. Then you have to make sure that What is your Theme that is being applied in AndroidManifest.xml.

如果在这样做之后,您不能看到您请求的更改。然后必须确保在AndroidManifest.xml中应用的主题是什么。

Also see that have you applied any style to activity?

还有,你对活动应用过什么风格吗?

just clear those things and this will work 100% correct.

只需要清除这些东西,这将会100%正确。

#2


155  

More simple, just set the buttonTint color: (only works on api level 21 or above)

更简单的是,只需设置buttonTint颜色:(只适用于api级别21或以上)

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/radio"
    android:checked="true"
    android:buttonTint="@color/your_color"/>

in your values/colors.xml put your color in this case a reddish one:

在你的价值观/颜色。xml将您的颜色设置为红色:

<color name="your_color">#e75748</color>

Result:

结果:

改变圆形按钮- Android按钮的颜色

If you want to do it by code (also api 21 and above):

如果您想通过代码(也包括api 21和以上)来完成:

if(Build.VERSION.SDK_INT>=21)
{

    ColorStateList colorStateList = new ColorStateList(
            new int[][]{

                    new int[]{-android.R.attr.state_enabled}, //disabled
                    new int[]{android.R.attr.state_enabled} //enabled
            },
            new int[] {

                    Color.BLACK //disabled
                    ,Color.BLUE //enabled

            }
        );                       


    radio.setButtonTintList(colorStateList);//set the color tint list
    radio.invalidate(); //could not be necessary
}

#3


112  

Update: 1. use this one instead

更新:1。用这个吧

   <android.support.v7.widget.AppCompatRadioButton
        android:id="@+id/rbtn_test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:buttonTint="@color/primary" />

2. Then add this line into parent layout or Alt + Enter in Android Studio to auto-add xmlns:app="http://schemas.android.com/apk/res-auto"

2。然后将这一行添加到父布局或Android Studio中的Alt + Enter,以自动添加xmlns:app="http://schemas.android.com/apk/res-auto"

Minimum Example should look like this:

最小的例子应该是这样的:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.AppCompatRadioButton
        android:id="@+id/rbtn_test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:buttonTint="@color/primary" />

</LinearLayout>

3. In your program, should call like this. AppCompatRadioButton radioButton = (AppCompatRadioButton) view.findViewById(R.id.rbtn_test);

3所示。在你的程序中,应该像这样调用。AppCompatRadioButton = (AppCompatRadioButton) view.findViewById(R.id.rbtn_test);

Basically, this kind of pattern can be applied for all AppCompact types such as AppCompatCheckBox, AppCompatButton and so on.

基本上,这种模式可以应用于所有AppCompact类型,如AppCompatCheckBox、AppCompatButton等。

Old Answer:

旧的回答:

In order to support below android API 21, you can use AppCompatRadioButton. Then use setSupportButtonTintList method to change the color. This is my code snippet to create a radio button .

为了支持下面的android API 21,您可以使用AppCompatRadioButton。然后使用setSupportButtonTintList方法更改颜色。这是我创建单选按钮的代码片段。

    AppCompatRadioButton rb;
    rb = new AppCompatRadioButton(mContext);

    ColorStateList colorStateList = new ColorStateList(
            new int[][]{
                    new int[]{-android.R.attr.state_checked},
                    new int[]{android.R.attr.state_checked}
            },
            new int[]{

                    Color.DKGRAY
                    , Color.rgb (242,81,112),
            }
    );
    rb.setSupportButtonTintList(colorStateList);

Tested result at API 19:

API 19测试结果:

改变圆形按钮- Android按钮的颜色

See the android reference link for more detail.

更多细节请参见android参考链接。

#4


63  

<android.support.v7.widget.AppCompatRadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:buttonTint="@color/Color" />

#5


38  

Working on API pre 21 as well as post 21. In your styles.xml put:

做API pre 21和post 21。在你的风格。xml将:

<!-- custom style -->
<style name="radionbutton"
       parent="Base.Widget.AppCompat.CompoundButton.RadioButton">
    <item name="android:button">@drawable/radiobutton_drawable</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:backgroundDimEnabled">true</item>
</style>

Your radio button in xml should look like:

xml中的单选按钮应该是这样的:

<RadioButton
    android:layout_width="wrap_content"
    style="@style/radionbutton"
    android:checked="false"
    android:layout_height="wrap_content"
    />

Now all you need to do is make a radiobutton_drawable.xml in your drawable folder. Here is what you need to put in it:

现在你需要做的就是制作一个radiobutton_drawable。可绘制文件夹中的xml。这是你需要放在里面的东西:

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

Your radio_unchecked.xml:

你的radio_unchecked.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="oval">
  <stroke android:width="1dp" android:color="@color/colorAccent"/>
  <size android:width="30dp" android:height="30dp"/>
</shape>

Your radio_checked.xml:

你的radio_checked.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <shape android:shape="oval">
      <stroke android:width="1dp" android:color="@color/colorAccent"/>
      <size android:width="30dp" android:height="30dp"/>
    </shape>
  </item>
  <item android:top="5dp" android:bottom="5dp" android:left="5dp" android:right="5dp">
    <shape android:shape="oval">
      <solid android:width="1dp" android:color="@color/colorAccent"/>
      <size android:width="10dp" android:height="10dp"/>
    </shape>
  </item>
</layer-list>

Just replace @color/colorAccent with the color of your choice.

只需将@color/colorAccent替换为您所选择的颜色。

#6


9  

Set the buttonTint property. For example, android:buttonTint="#99FF33".

设置buttonTint属性。例如,android:buttonTint = " # 99 ff33”。

#7


9  

The question is old but i think my answer will help people. You can change the color of radio button's unchecked and checked state by using style in xml.

这个问题已经过时了,但我认为我的答案会对人们有所帮助。您可以使用xml中的样式更改单选按钮的未检查和检查状态的颜色。

<RadioButton
    android:id="@+id/rb"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:theme="@style/RadioButtonStyle" />

In style.xml

在style.xml

<style name="RadioButtonStyle" parent="Theme.AppCompat.Light">
        <item name="colorAccent">@android:color/white</item>
        <item name="android:textColorSecondary">@android:color/white</item>
</style>

You can set the desired colors in this style.

您可以在此样式中设置所需的颜色。

#8


8  

You have to use this code:

您必须使用以下代码:

<android.support.v7.widget.AppCompatRadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:buttonTint="@color/black"
                    android:text="Radiobutton1"
                    app:buttonTint="@color/black" />

Using app:buttonTint instead of android:buttonTint and also android.support.v7.widget.AppCompatRadioButton instead of Radiobutton!

使用app:buttonTint而不是android:buttonTint,还有android.support.v7.widget。AppCompatRadioButton代替Radiobutton !

#9


4  

There is an xml attribute for it:

它有一个xml属性:

android:buttonTint="yourcolor"

#10


2  

Sometimes you just need to override colorControlNormal like this:

有时候你只需要像这样覆盖colorControlNormal:

    <style name="RadioButtonStyle" parent="AppTheme">
       <item name="colorControlNormal">@color/pink</item>
       <item name="colorAccent">@color/colorPrimary</item>
       <item name="android:textColorSecondary">@color/black</item>
    </style>

And you will get a button like this:

你会得到这样一个按钮:

改变圆形按钮- Android按钮的颜色

colorControlNormal used for unchecked state and colorAccent for checked.

colorControlNormal用于检查未检查的状态和colorAccent。

#11


1  

I made it short way like this (Working on API pre 21 as well as post 21)

我做得很简短,就像这样(做API pre 21和post 21)

Your radio button in xml should look like this

xml中的单选按钮应该是这样的

  <RadioButton android:id="@+id/radioid"                    
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"                 
                android:button="@drawable/radiodraw" />

in radiodraw.xml

在radiodraw.xml

  <?xml version="1.0" encoding="utf-8"?>
  <selector xmlns:android="http://schemas.android.com/apk/res/android">    
      <item android:state_checked="false" >
          <shape  android:shape="oval" >
              <stroke android:width="1dp" android:color="#000"/>
              <size android:width="30dp" android:height="30dp"/>
              <solid android:color="@android:color/transparent"/>
          </shape>
      </item>
      <item android:state_checked="true">
          <layer-list>
              <item>
                  <shape android:shape="oval">
                      <stroke android:width="1dp" android:color="#000"/>
                      <size android:width="30dp" android:height="30dp"/>
                      <solid android:color="@android:color/transparent"/>
                  </shape>
              </item>
              <item android:top="5dp" android:bottom="5dp" android:left="5dp" android:right="5dp">
                  <shape android:shape="oval">
                      <solid android:width="1dp" android:color="#000"/>
                      <size android:width="10dp" android:height="10dp"/>
                  </shape>
              </item>
          </layer-list>
      </item>
  </selector>

have to add color transparent for drawing the unchecked status ;else it draw solid black oval.

必须添加透明的颜色来绘制未选中的状态;否则它将绘制纯黑色的椭圆形。

#12


1  

RadioButton by default takes the colour of colorAccent in res/values/colors.xml file. So go to that file and change the value of

默认情况下,RadioButton获取res/values/color中的colorAccent颜色。xml文件。所以切换到那个文件,改变它的值。

<color name="colorAccent">#3F51B5</color>

<颜色名称= " coloraccent> # 3 f51b5 > < /颜色

to the colour you want.

到你想要的颜色。

#13


1  

  1. Declare custom style in your styles.xml file.

    在样式中声明自定义样式。xml文件。

    <style name="MyRadioButton" parent="Theme.AppCompat.Light">  
      <item name="colorControlNormal">@color/indigo</item>
      <item name="colorControlActivated">@color/pink</item>
    </style>  
    
  2. Apply this style to your RadioButton via android:theme attribute.

    通过android:theme属性将此样式应用到您的RadioButton上。

    <RadioButton  
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="Radio Button"
        android:theme="@style/MyRadioButton"/>
    

    only if your activity extends AppCompatActivity

    只有当您的活动扩展AppCompatActivity时

#14


0  

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/radio"
    android:buttonTint="@color/my_color"/>

All button will change color, the circle box and the central check.

所有的按钮将改变颜色,圆形框和*复选框。

#15


0  

The easiest way is to change colourAccent color in values->colours.xml
but be aware that it will also change other things like edit text cursor color etc..

最简单的方法是改变颜色重音颜色的值->颜色。但是要注意,它还会改变其他东西,比如编辑文本光标颜色等等。

< color name="colorAccent">#75aeff</color >

<颜色名称= " coloraccent> # 75 aeff > < /颜色

#16


-3  

@jh314 is correct. In AndroidManifest.xml,

@jh314是正确的。在AndroidManifest.xml,

 <application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"></application>

In style.xml

在style.xml

  <!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorAccent">@color/red</item>
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

the item name must be colorAccent,it decides the application's widgets default color.

项目名称必须是colorAccent,它决定应用程序的小部件的默认颜色。

But if you want to change the color in code,Maybe @aknay's answer is correct.

但是如果你想改变代码的颜色,也许@aknay的答案是正确的。

#1


28  

This site is really good for customizing Android components in general: http://android-holo-colors.com/

这个网站非常适合定制Android组件:http://android-holo-colors.com/

Just choose the radio button, make the color white, download, and profit!

只要选择单选按钮,使颜色变白,下载,利润!

More Information

更多的信息

If after doing that you cannot see your requested change. Then you have to make sure that What is your Theme that is being applied in AndroidManifest.xml.

如果在这样做之后,您不能看到您请求的更改。然后必须确保在AndroidManifest.xml中应用的主题是什么。

Also see that have you applied any style to activity?

还有,你对活动应用过什么风格吗?

just clear those things and this will work 100% correct.

只需要清除这些东西,这将会100%正确。

#2


155  

More simple, just set the buttonTint color: (only works on api level 21 or above)

更简单的是,只需设置buttonTint颜色:(只适用于api级别21或以上)

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/radio"
    android:checked="true"
    android:buttonTint="@color/your_color"/>

in your values/colors.xml put your color in this case a reddish one:

在你的价值观/颜色。xml将您的颜色设置为红色:

<color name="your_color">#e75748</color>

Result:

结果:

改变圆形按钮- Android按钮的颜色

If you want to do it by code (also api 21 and above):

如果您想通过代码(也包括api 21和以上)来完成:

if(Build.VERSION.SDK_INT>=21)
{

    ColorStateList colorStateList = new ColorStateList(
            new int[][]{

                    new int[]{-android.R.attr.state_enabled}, //disabled
                    new int[]{android.R.attr.state_enabled} //enabled
            },
            new int[] {

                    Color.BLACK //disabled
                    ,Color.BLUE //enabled

            }
        );                       


    radio.setButtonTintList(colorStateList);//set the color tint list
    radio.invalidate(); //could not be necessary
}

#3


112  

Update: 1. use this one instead

更新:1。用这个吧

   <android.support.v7.widget.AppCompatRadioButton
        android:id="@+id/rbtn_test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:buttonTint="@color/primary" />

2. Then add this line into parent layout or Alt + Enter in Android Studio to auto-add xmlns:app="http://schemas.android.com/apk/res-auto"

2。然后将这一行添加到父布局或Android Studio中的Alt + Enter,以自动添加xmlns:app="http://schemas.android.com/apk/res-auto"

Minimum Example should look like this:

最小的例子应该是这样的:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.AppCompatRadioButton
        android:id="@+id/rbtn_test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:buttonTint="@color/primary" />

</LinearLayout>

3. In your program, should call like this. AppCompatRadioButton radioButton = (AppCompatRadioButton) view.findViewById(R.id.rbtn_test);

3所示。在你的程序中,应该像这样调用。AppCompatRadioButton = (AppCompatRadioButton) view.findViewById(R.id.rbtn_test);

Basically, this kind of pattern can be applied for all AppCompact types such as AppCompatCheckBox, AppCompatButton and so on.

基本上,这种模式可以应用于所有AppCompact类型,如AppCompatCheckBox、AppCompatButton等。

Old Answer:

旧的回答:

In order to support below android API 21, you can use AppCompatRadioButton. Then use setSupportButtonTintList method to change the color. This is my code snippet to create a radio button .

为了支持下面的android API 21,您可以使用AppCompatRadioButton。然后使用setSupportButtonTintList方法更改颜色。这是我创建单选按钮的代码片段。

    AppCompatRadioButton rb;
    rb = new AppCompatRadioButton(mContext);

    ColorStateList colorStateList = new ColorStateList(
            new int[][]{
                    new int[]{-android.R.attr.state_checked},
                    new int[]{android.R.attr.state_checked}
            },
            new int[]{

                    Color.DKGRAY
                    , Color.rgb (242,81,112),
            }
    );
    rb.setSupportButtonTintList(colorStateList);

Tested result at API 19:

API 19测试结果:

改变圆形按钮- Android按钮的颜色

See the android reference link for more detail.

更多细节请参见android参考链接。

#4


63  

<android.support.v7.widget.AppCompatRadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:buttonTint="@color/Color" />

#5


38  

Working on API pre 21 as well as post 21. In your styles.xml put:

做API pre 21和post 21。在你的风格。xml将:

<!-- custom style -->
<style name="radionbutton"
       parent="Base.Widget.AppCompat.CompoundButton.RadioButton">
    <item name="android:button">@drawable/radiobutton_drawable</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:backgroundDimEnabled">true</item>
</style>

Your radio button in xml should look like:

xml中的单选按钮应该是这样的:

<RadioButton
    android:layout_width="wrap_content"
    style="@style/radionbutton"
    android:checked="false"
    android:layout_height="wrap_content"
    />

Now all you need to do is make a radiobutton_drawable.xml in your drawable folder. Here is what you need to put in it:

现在你需要做的就是制作一个radiobutton_drawable。可绘制文件夹中的xml。这是你需要放在里面的东西:

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

Your radio_unchecked.xml:

你的radio_unchecked.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="oval">
  <stroke android:width="1dp" android:color="@color/colorAccent"/>
  <size android:width="30dp" android:height="30dp"/>
</shape>

Your radio_checked.xml:

你的radio_checked.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <shape android:shape="oval">
      <stroke android:width="1dp" android:color="@color/colorAccent"/>
      <size android:width="30dp" android:height="30dp"/>
    </shape>
  </item>
  <item android:top="5dp" android:bottom="5dp" android:left="5dp" android:right="5dp">
    <shape android:shape="oval">
      <solid android:width="1dp" android:color="@color/colorAccent"/>
      <size android:width="10dp" android:height="10dp"/>
    </shape>
  </item>
</layer-list>

Just replace @color/colorAccent with the color of your choice.

只需将@color/colorAccent替换为您所选择的颜色。

#6


9  

Set the buttonTint property. For example, android:buttonTint="#99FF33".

设置buttonTint属性。例如,android:buttonTint = " # 99 ff33”。

#7


9  

The question is old but i think my answer will help people. You can change the color of radio button's unchecked and checked state by using style in xml.

这个问题已经过时了,但我认为我的答案会对人们有所帮助。您可以使用xml中的样式更改单选按钮的未检查和检查状态的颜色。

<RadioButton
    android:id="@+id/rb"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:theme="@style/RadioButtonStyle" />

In style.xml

在style.xml

<style name="RadioButtonStyle" parent="Theme.AppCompat.Light">
        <item name="colorAccent">@android:color/white</item>
        <item name="android:textColorSecondary">@android:color/white</item>
</style>

You can set the desired colors in this style.

您可以在此样式中设置所需的颜色。

#8


8  

You have to use this code:

您必须使用以下代码:

<android.support.v7.widget.AppCompatRadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:buttonTint="@color/black"
                    android:text="Radiobutton1"
                    app:buttonTint="@color/black" />

Using app:buttonTint instead of android:buttonTint and also android.support.v7.widget.AppCompatRadioButton instead of Radiobutton!

使用app:buttonTint而不是android:buttonTint,还有android.support.v7.widget。AppCompatRadioButton代替Radiobutton !

#9


4  

There is an xml attribute for it:

它有一个xml属性:

android:buttonTint="yourcolor"

#10


2  

Sometimes you just need to override colorControlNormal like this:

有时候你只需要像这样覆盖colorControlNormal:

    <style name="RadioButtonStyle" parent="AppTheme">
       <item name="colorControlNormal">@color/pink</item>
       <item name="colorAccent">@color/colorPrimary</item>
       <item name="android:textColorSecondary">@color/black</item>
    </style>

And you will get a button like this:

你会得到这样一个按钮:

改变圆形按钮- Android按钮的颜色

colorControlNormal used for unchecked state and colorAccent for checked.

colorControlNormal用于检查未检查的状态和colorAccent。

#11


1  

I made it short way like this (Working on API pre 21 as well as post 21)

我做得很简短,就像这样(做API pre 21和post 21)

Your radio button in xml should look like this

xml中的单选按钮应该是这样的

  <RadioButton android:id="@+id/radioid"                    
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"                 
                android:button="@drawable/radiodraw" />

in radiodraw.xml

在radiodraw.xml

  <?xml version="1.0" encoding="utf-8"?>
  <selector xmlns:android="http://schemas.android.com/apk/res/android">    
      <item android:state_checked="false" >
          <shape  android:shape="oval" >
              <stroke android:width="1dp" android:color="#000"/>
              <size android:width="30dp" android:height="30dp"/>
              <solid android:color="@android:color/transparent"/>
          </shape>
      </item>
      <item android:state_checked="true">
          <layer-list>
              <item>
                  <shape android:shape="oval">
                      <stroke android:width="1dp" android:color="#000"/>
                      <size android:width="30dp" android:height="30dp"/>
                      <solid android:color="@android:color/transparent"/>
                  </shape>
              </item>
              <item android:top="5dp" android:bottom="5dp" android:left="5dp" android:right="5dp">
                  <shape android:shape="oval">
                      <solid android:width="1dp" android:color="#000"/>
                      <size android:width="10dp" android:height="10dp"/>
                  </shape>
              </item>
          </layer-list>
      </item>
  </selector>

have to add color transparent for drawing the unchecked status ;else it draw solid black oval.

必须添加透明的颜色来绘制未选中的状态;否则它将绘制纯黑色的椭圆形。

#12


1  

RadioButton by default takes the colour of colorAccent in res/values/colors.xml file. So go to that file and change the value of

默认情况下,RadioButton获取res/values/color中的colorAccent颜色。xml文件。所以切换到那个文件,改变它的值。

<color name="colorAccent">#3F51B5</color>

<颜色名称= " coloraccent> # 3 f51b5 > < /颜色

to the colour you want.

到你想要的颜色。

#13


1  

  1. Declare custom style in your styles.xml file.

    在样式中声明自定义样式。xml文件。

    <style name="MyRadioButton" parent="Theme.AppCompat.Light">  
      <item name="colorControlNormal">@color/indigo</item>
      <item name="colorControlActivated">@color/pink</item>
    </style>  
    
  2. Apply this style to your RadioButton via android:theme attribute.

    通过android:theme属性将此样式应用到您的RadioButton上。

    <RadioButton  
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="Radio Button"
        android:theme="@style/MyRadioButton"/>
    

    only if your activity extends AppCompatActivity

    只有当您的活动扩展AppCompatActivity时

#14


0  

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/radio"
    android:buttonTint="@color/my_color"/>

All button will change color, the circle box and the central check.

所有的按钮将改变颜色,圆形框和*复选框。

#15


0  

The easiest way is to change colourAccent color in values->colours.xml
but be aware that it will also change other things like edit text cursor color etc..

最简单的方法是改变颜色重音颜色的值->颜色。但是要注意,它还会改变其他东西,比如编辑文本光标颜色等等。

< color name="colorAccent">#75aeff</color >

<颜色名称= " coloraccent> # 75 aeff > < /颜色

#16


-3  

@jh314 is correct. In AndroidManifest.xml,

@jh314是正确的。在AndroidManifest.xml,

 <application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"></application>

In style.xml

在style.xml

  <!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorAccent">@color/red</item>
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

the item name must be colorAccent,it decides the application's widgets default color.

项目名称必须是colorAccent,它决定应用程序的小部件的默认颜色。

But if you want to change the color in code,Maybe @aknay's answer is correct.

但是如果你想改变代码的颜色,也许@aknay的答案是正确的。