android 点击变色的两种情况、textview点击变色以及自定义checkbox
2017-05-12 14:32
369 查看
注意,对于布局类型的,设置clickable=true
1.不需要使用shape的情况
drawable下新建一个资源文件,在需要的地方setbackground
2.需要设置圆角等等需要自定义shape的,和1类似,只是里面的drawable="@color"换做@drawable
3.自定义checkbox
设置checkbox @Android:button="@null",而后设置background
backgroud使用的xml文件如下:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shi_tab" android:state_checked="true"></item>
<item android:drawable="@drawable/fou_tab" android:state_checked="false"></item>
</selector>
1.不需要使用shape的情况
drawable下新建一个资源文件,在需要的地方setbackground
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@color/del"/> <item android:state_pressed="false" android:drawable="@color/main_color"/> </selector>
2.需要设置圆角等等需要自定义shape的,和1类似,只是里面的drawable="@color"换做@drawable
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false" android:drawable="@drawable/fillet_rectangle_5dp_bg"/> <item android:state_pressed="true" android:drawable="@drawable/login_shape_two"/> </selector>3.textview的点击变色
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:color="@color/del"></item> <item android:color="@color/main_color"/> </selector>不能和上面的一样设置,否则颜色会和设定的不一致,原因不详
3.自定义checkbox
设置checkbox @Android:button="@null",而后设置background
backgroud使用的xml文件如下:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shi_tab" android:state_checked="true"></item>
<item android:drawable="@drawable/fou_tab" android:state_checked="false"></item>
</selector>
相关文章推荐
- android中TextView 添加ClickableSpan后点击选中文字背景变色问题
- Android TextView 给文本中指定片段添加自定义点击事件
- android 自定义TextView中Html超链接点击事件详解
- Android-自定义TextView(彩色字体与霓虹灯字体以及TextView的多项字体效果)
- android开发之自定义TextView设置字间距以及通过TextView控件属性设置行间距
- android TextView 实现自定义文字点击效果
- TextView自定义省略号、部分文字变色、部分文字点击
- Android使用RecyclerView实现自定义列表、点击事件以及下拉刷新
- 自定义圆角点击变色TextView
- android 自定义TextView支持微博功能后在ListView占用了Item点击的解决办法
- android 自定义TextView支持微博功能后在ListView占用了Item点击的解决办法
- Android 自定义TextView 实现文字对齐排版且支持点击划词
- Android自动识别<a>标签的自定义TextView(可自定义点击事件)
- Android自定义TextView中的超链接点击事件处理
- Android的控件CheckBox、ImageView以及ListView的自定义Adapter用法
- Android自定义TextView链接点击和长按事件
- Android自定义TextView中的超链接点击事件处理
- android笔记 自定义textview,button等控件的外观,点击效果
- android 在listview中实现点击textview改变checkbox的状态
- Android自定义控件3:带边框点击背景变色的textview,原型是支付宝手机充值中话费充值按钮