单选按钮样式修改RadioButton

Android CheckBox修改大小、边框颜色,以及自定义CheckBox;_android checkbox动态添加设置方框颜色-CSDN博客

复制代码
<RadioGroup
	android:id="@+id/login_radio_group"
	android:layout_width="match_parent"
	android:layout_height="wrap_content"
	android:orientation="horizontal"
	app:layout_constraintLeft_toLeftOf="parent"
	app:layout_constraintRight_toRightOf="parent"
	app:layout_constraintTop_toTopOf="parent">

	<RadioButton
		android:id="@+id/login_rb_1"
		android:layout_width="0dp"
		android:layout_height="wrap_content"
		android:layout_weight="1"
		android:background="@drawable/login_rb_bg_sel"
		android:button="@null"
		android:checked="true"
		android:gravity="center"
		android:text="账号登录"
		android:textColor="@color/white" />

	<RadioButton
		android:id="@+id/login_rb_2"
		android:layout_width="0dp"
		android:layout_height="wrap_content"
		android:layout_weight="1"
		android:background="@drawable/login_rb_bg_sel"
		android:button="@null"
		android:gravity="center"
		android:text="刷卡登录"
		android:textColor="@color/white" />

	<RadioButton
		android:id="@+id/login_rb_3"
		android:layout_width="0dp"
		android:layout_height="wrap_content"
		android:layout_weight="1"
		android:background="@drawable/login_rb_bg_sel"
		android:button="@null"
		android:gravity="center"
		android:text="指纹登录"
		android:textColor="@color/white" />

	<RadioButton

		android:id="@+id/login_rb_4"
		android:layout_width="0dp"
		android:layout_height="wrap_content"
		android:layout_weight="1"
		android:background="@drawable/login_rb_bg_sel"
		android:button="@null"
		android:gravity="center"
		android:text="人脸登录"
		android:textColor="@color/white" />
</RadioGroup>
			
			
login_rb_bg_sel.xml
				
	<?xml version="1.0" encoding="utf-8"?>
	<selector xmlns:android="http://schemas.android.com/apk/res/android">
		<item android:drawable="@drawable/login_rb_bg_shape_unchecked" android:state_checked="false"></item>
		<item android:drawable="@drawable/login_rb_bg_shape_checked" android:state_checked="true"></item>
	</selector>
	
login_rb_bg_shape_unchecked.xml

	<?xml version="1.0" encoding="utf-8"?>
	<shape xmlns:android="http://schemas.android.com/apk/res/android"
		android:shape="rectangle">
		<!-- 填充 -->
		<solid android:color="@color/login_rb_un_sel" />
		<!-- 圆角 -->
		<!--    <corners android:radius="5dp" />-->
		<padding
			android:bottom="3dp"
			android:left="@dimen/dp_1"
			android:right="@dimen/dp_1"
			android:top="3dp" />
		<stroke
			android:width="1dp"
			android:color="#CCCCCC" />
	</shape>

login_rb_bg_shape_checked.xml

	<?xml version="1.0" encoding="utf-8"?>
	<shape xmlns:android="http://schemas.android.com/apk/res/android"
		android:shape="rectangle">
		<!-- 填充 -->
		<solid android:color="@color/login_rb_sel" />
		<!-- 圆角 -->
		<!--    <corners android:radius="5dp" />-->

		<padding
			android:bottom="3dp"
			android:left="@dimen/dp_1"
			android:right="@dimen/dp_1"
			android:top="3dp" />
		<stroke
			android:width="1dp"
			android:color="#CCCCCC" />
	</shape>
	
----------------------------------------------------------------------------------------------------
Android CheckBox修改大小、边框颜色,以及自定义CheckBox;

CheckBox修改大小:
	android:scaleX="0.8"
	android:scaleY="0.8"
CheckBox修改边框颜色,注意不是背景色:
	 android:buttonTint="@color/colorAccent"
修改大小和边框颜色:
	   <CheckBox
		android:layout_width="wrap_content"
		android:layout_height="match_parent"
		android:gravity="center_vertical"
		android:scaleX="0.8"
		android:scaleY="0.8"
		android:buttonTint="@color/colorAccent"
		/>
自定义CheckBox:
    <CheckBox
		android:id="@+id/spc_cb_shops"
		android:layout_width="wrap_content"
		android:layout_height="match_parent"
		android:paddingLeft="@dimen/side_distance"
		android:paddingRight="@dimen/side_distance"
		style="@style/spc_checkbox_style"
		/>
	
	<!--购物车checkbox-->
    <style name="spc_checkbox_style" parent="@android:style/Widget.CompoundButton.CheckBox">
        <item name="android:drawableLeft">@drawable/spc_cb</item>
        <item name="android:button">@null</item>
    </style>
	
	<?xml version="1.0" encoding="utf-8"?>
	<selector xmlns:android="http://schemas.android.com/apk/res/android">
		<item android:state_checked="true" android:drawable="@mipmap/select_button" />
		<item android:state_checked="false" android:drawable="@mipmap/select_button_gray" />
		<item android:drawable="@mipmap/select_button_gray" />
	</selector>

@mipmap/select_button是已选中样式,;
@mipmap/select_button_gray是未选中样式;
相关推荐
知行力23 分钟前
【GitHub每日速递 20251219】Claude-Mem:持久内存压缩系统,为Claude Code带来上下文连续性新体验!
github
薛定e的猫咪1 小时前
覆盖文献到写作全流程!GPT-Academic 多模型学术助手安装与使用指南
人工智能·gpt·github
鸽鸽程序猿2 小时前
【Redis】Java客户端使用Redis
java·redis·github
m0_726365833 小时前
大力学习台灯T6/T6Pro 救砖实战:macOS/Windows 用 mtkclient 从 Fastboot 无限重启完整恢复(含固件下载地址)
python·github·智能硬件
Mr.zwX4 小时前
如何用vscode/cursor快速绑定并操作远程Github仓库
ide·vscode·github
JustHappy15 小时前
「chrome extensions🛠️」我写了一个超级简单的浏览器插件Vue开发模板
前端·javascript·github
阿里嘎多学长16 小时前
2025-12-16 GitHub 热点项目精选
开发语言·程序员·github·代码托管
缘不易16 小时前
Springboot 整合JustAuth实现gitee授权登录
spring boot·后端·gitee
五月底_17 小时前
上传大量文件到github repo
git·github
KnowFlow企业知识库19 小时前
KnowFlow v2.3.0 重磅发布:适配 RAGFlow v0.22.1 和 MinerU v2.6.5、新增支持多模态视频解析,让知识库"看见"更多
linux·github