【问题标题】:How to change border color of radio button in android? [duplicate]如何更改android中单选按钮的边框颜色? [复制]
【发布时间】:2013-04-19 06:07:36
【问题描述】:

如何更改android中单选按钮的边框颜色?

我想改变android单选按钮的圆圈颜色。

提前致谢。非常感谢任何帮助。

我尝试了不同的解决方案,并担心是否有任何其他可绘制图像的属性

【问题讨论】:

标签: android android-ui


【解决方案1】:

是的,这是您要查找的属性: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"/>

在您的 values/colors.xml 中将您的颜色设置为微红色:

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

结果:

【讨论】:

  • 据我所知,这只适用于 api 级别 21 或更高级别。这意味着它不会对较低版本的android产生影响。
  • 你说得对,我忘了说,谢谢,我已经更新了帖子以包含它
【解决方案2】:

自定义(更改颜色)视图的最简单方法。

转到:http://android-holo-colors.com/

  • 为单选按钮选择所需的颜色
  • 下载输出资源 (Download.Zip)
  • 解压 zip 内容
  • 将文件从解压缩的 zip 文件复制到项目的可绘制对象、样式和值中
  • 将应用主题的父主题更改为您下载的主题
  • 你得到了你想要的

【讨论】:

    【解决方案3】:

    尝试使用 AppCompatRadioButton

    <android.support.v7.widget.AppCompatRadioButton
        android:id="@+id/rb"
        app:buttonTint="@color/colorAccent" //This to set your default button color
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    

    欲了解更多详情,请查看此答案:Android: Change the color of RadioButtons and checkboxes programmatically

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-19
      • 2017-09-21
      • 1970-01-01
      • 1970-01-01
      • 2018-01-31
      • 2012-03-29
      • 1970-01-01
      相关资源
      最近更新 更多