Android RadioButton,定制按钮样式

1.定义选中和非选中的样式选择器;res/drawable/custom_radio_button.xml

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

2.在布局文件中设置background,取消原生的button

<RadioButton
        android:id="@+id/home_rb"
        android:layout_width="@dimen/dp_20"
        android:layout_height="@dimen/dp_20"
        app:layout_constraintStart_toEndOf="@+id/home_listView_tv"
        android:button="@null"//重要
        android:background="@drawable/custom_radio_button"//重要
        android:layout_marginEnd="@dimen/dp_10"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

相关推荐

  1. Android RadioButton,定制按钮样式

    2024-05-12 22:58:05       33 阅读
  2. wpf 按钮禁用样式

    2024-05-12 22:58:05       34 阅读
  3. C#WPF设置圆角按钮样式

    2024-05-12 22:58:05       33 阅读
  4. 定义 按钮间,按钮边框滑动。

    2024-05-12 22:58:05       61 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-12 22:58:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-12 22:58:05       100 阅读
  3. 在Django里面运行非项目文件

    2024-05-12 22:58:05       82 阅读
  4. Python语言-面向对象

    2024-05-12 22:58:05       91 阅读

热门阅读

  1. Vue router(路由守卫)

    2024-05-12 22:58:05       28 阅读
  2. 大话C语言:第11篇 运算符之自增减运算符

    2024-05-12 22:58:05       31 阅读
  3. video.js的请求头问题

    2024-05-12 22:58:05       26 阅读
  4. 算法学习笔记(Nim游戏)

    2024-05-12 22:58:05       34 阅读
  5. 蓝桥杯备战12.阶乘

    2024-05-12 22:58:05       39 阅读
  6. 基于单片机的宠物智能投喂系统研究

    2024-05-12 22:58:05       31 阅读
  7. 如何excel里面数据格式设置为utf-8

    2024-05-12 22:58:05       28 阅读
  8. 使用 git rebase 还是 git merge,优缺点

    2024-05-12 22:58:05       28 阅读