Android:使用selector 在 button上无效的问题
来源:互联网 发布:大数据时代变革 编辑:程序博客网 时间:2024/05/01 10:15
我们常常会写button 点击变色(获焦点),失焦恢复颜色这样:
很简单,在drawable写一个xml,selector中,判断 textcolor 就可以了,
selector还可以写其他有趣的事情,比如描边,圆角,填充,设置内边距等等;
但是在button中是无效的!如果用代码写的话,又太费劲....
<Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="无价值" android:textColor="@drawable/auto_textonclick" android:background="@drawable/auto_bgonclick" android:layout_marginLeft="10dp" android:gravity="center"/>
正常的Button 是没用的,所以,我们用RadioButton !
<!-- 评分按钮 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="10dp"><RadioGroup android:layout_width="match_parent" android:layout_height="35dp" android:orientation="horizontal"> <RadioButton android:id="@+id/noJz" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="无价值" android:textColor="@drawable/auto_textonclick" android:background="@drawable/auto_bgonclick" android:button="@null" android:layout_marginLeft="10dp" android:gravity="center"/> <RadioButton android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="还可以" android:textColor="@drawable/auto_textonclick" android:background="@drawable/auto_bgonclick" android:button="@null" android:gravity="center" android:layout_marginLeft="10dp"/> <RadioButton android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="有价值" android:textColor="@drawable/auto_textonclick" android:background="@drawable/auto_bgonclick" android:button="@null" android:gravity="center" android:layout_marginLeft="10dp"/></RadioGroup> </LinearLayout>
auto_textview.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" ><!-- 得到焦点:白色 --> <item android:color="@android:color/white" android:state_checked="true" /><!-- 默认:红色 --> <item android:color="@android:color/holo_red_light"/></selector>
auto_bgonclick
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/all_red" android:state_checked="true"/> <item android:drawable="@drawable/bai_red"/></selector>
selector还可以写其他有趣的事情,比如描边,圆角,填充,设置内边距等等:
iconbg.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 描边 --> <stroke android:width="0.5dp" android:color="@color/Chuise3"/> <!-- 填充 --> <solid android:color="@android:color/white"/> <!-- 圆角 --> <corners android:radius="8dp"/> <!-- 内容与边框间距 --></shape>
背景引用:
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_margin="5dp" android:padding="10dp" android:background="@drawable/iconbg">.......内容</LinearLayout>
是不是很简单啊?
0 0
- android 使用selector 在 button上无效的问题(汇总)
- Android:使用selector 在 button上无效的问题
- android使用selector在 button上无效
- Android 使用selector设置button字体颜色无效
- Button selector的使用
- Android selector shape 无效问题
- android中selector在java代码中使用无效的解决方案
- android中selector在java代码中使用无效的解决方案
- Button的背景使用selector图片无法显示的问题
- Android Button的Selector+Shape
- 解决在Android中给Button设置Padding无效的问题
- android button selector disable 样式问题
- Android-----使用Button特效selector+shape
- Android-----使用Button特效 selector+shape
- android 关于Button在StateListDrawable 中使用AnimationDrawable的问题
- 关于给Button设置selector的问题
- android selector 使用中常见的问题
- Android标准的Button的selector
- 自己做个MP3_硬件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- Maven工程下使用SVN上传和下载代码
- 0224
- 机器学习->推荐系统->利用用户标签数据
- Android:使用selector 在 button上无效的问题
- 程序员需要具备的基本技能
- GIT笔记
- Android原生音量控制
- 2017.3.24信息课c++
- android好玩的项目
- 深入理解编译注解(六)Butterknife的实现原理
- 确看待百度预估流量为0的问题-cuug
- activity之间的通讯方式总结