Android新手之旅(7) RadioButton的自定义
希望用到RadioGroup的功能,但遇到一些看似简单问题却无法解决:系统的图标太大却难以更换,在网上找解决方案。有些地方提到,由于用的是图片,所以无法缩小,只好自定义,参考1 参考2
然后,找图标,在sdk文件夹下搜索含radio的文件,很多,选一套合适的即可。
这是在res/drawable下的radiobutton.xml文件
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="true"
android:state_checked="true"
android:drawable="@drawable/check" />
<item
android:state_enabled="true"
android:state_checked="false"
android:drawable="@drawable/checknull" />
</selector>这是radiogroup的定义。注意:
1、RadioGroup 方向是水平,android:orientation="horizontal" 。
2、button的样式是android:button = "@drawable/radiobutton"。为了找这个属性费了大劲了。
<RadioGroup android:id="@+id/radioGroup1" android:paddingTop="30px" android:paddingLeft="15px" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" >
<RadioButton android:text="今天" android:layout_width="wrap_content" android:textSize="14px" android:checked="true" android:layout_height="wrap_content" android:editable="false" android:id="@+id/radio0" android:button = "@drawable/radiobutton" android:paddingLeft="30px" android:layout_marginRight="2px" android:textColor="#000"></RadioButton>
<RadioButton android:text="昨天" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/radio1" android:textSize="14px" android:button = "@drawable/radiobutton" android:paddingLeft="30px" android:layout_marginRight="2px" android:textColor="#000"></RadioButton>
<RadioButton android:text="前天" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/radio2" android:textSize="14px" android:button = "@drawable/radiobutton" android:paddingLeft="30px" android:layout_marginRight="2px" android:textColor="#000"></RadioButton>
</RadioGroup>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」
2010-07-24 异步方式访问网页
2008-07-24 VB显示真彩图标
2007-07-24 如何清除应用程序承载 WebBrowser 控件时缓存
2005-07-24 最近读的文章