Android SwitchCompat开关按钮自定义颜色和样式
来源:互联网 发布:小米3能用联通4g网络吗 编辑:程序博客网 时间:2024/06/08 13:51
Android SwitchCompat开关按钮自定义颜色和样式
1、改变轨迹颜色
- 只改变原生的轨迹颜色,不改变样式
用trackTint属性,例:
<android.support.v7.widget.SwitchCompat android:layout_width="wrap_content" android:layout_height="wrap_content" app:trackTint="#464c57" />
- 改变成自己想要的样式
用switch_track属性,例:
<android.support.v7.widget.SwitchCompat android:layout_width="wrap_content" android:layout_height="wrap_content" android:track="@drawable/switch_track" />
switch_track.xml内容:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/switch_track_on"/> <item android:state_checked="false" android:drawable="@drawable/switch_track_off"/></selector>
switch_track_on.xml内容
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#464c57"> </solid> <corners android:radius="10dp"> </corners></shape>
switch_track_off.xml内容:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#464c57"> </solid> <corners android:radius="10dp"> </corners></shape>
2、改变按钮颜色
- 只改变原生的背景颜色,不改变样式
可以用thumbTint属性,代码同上,用这个属性无论状态“开”,“关”,颜色一样 - 改变成自己想要的样式
用thumb属性:
<android.support.v7.widget.SwitchCompat android:layout_width="wrap_content" android:layout_height="wrap_content" android:thumb="@drawable/switch_thum" />
switch_thum.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/switch_thum_on"/> <item android:state_checked="false" android:drawable="@drawable/switch_thum_off"/></selector>
switch_thum_on.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <size android:width="20dp" android:height="20dp"> </size> <solid android:color="#92e843"> </solid></shape>
switch_thum_off.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <size android:width="20dp" android:height="20dp"> </size> <solid android:color="#818a95"> </solid></shape>
阅读全文
0 0
- Android SwitchCompat开关按钮自定义颜色和样式
- Android 自定义Switch开关按钮的样式
- Android SwitchCompat 自定义颜色 及使用
- Android自定义开关按钮
- android 自定义开关按钮
- Android自定义开关按钮
- android 自定义开关按钮
- android switchCompat代码设置颜色
- android自定义开关、图片按钮
- Android 中的自定义开关按钮
- Android 自定义绘制开关按钮
- Android 自定义仿微信开关按钮
- Android自定义按钮样式
- android 自定义按钮样式
- Android自定义View之自定义开关按钮
- Android 自定义实现switch开关按钮
- android 自定义竖开关按钮 SwitchButton
- Android 自定义实现switch开关按钮
- VISUALS USED BY THE FRAME BUFFER DEVICE API
- android中在onNewIntent实现刷新数据
- Building an MFC project for a non-Unicode character set is deprecated
- 软考笔记0609软件文档三种类别
- Spring 3整合Quartz 2实现定时任务:动态添加任务
- Android SwitchCompat开关按钮自定义颜色和样式
- Vue项目中添加service worker
- 用逆波兰表达式的三角函数计算器
- MySQL日期数据类型、时间类型使用总结
- spring-oauth集成cas单点登录,登陆完成进入授权页面后,按回退按钮进入404页面的问题
- org.apache.maven.archiver.mavenarchiver.getmanifest怎么解决
- 多语言混合开发
- 佛说疗痔病经
- 【方法】搜索排序评估方法