关于Switch控件的使用
来源:互联网 发布:淘宝美食店铺吐血推荐 编辑:程序博客网 时间:2024/06/06 08:41
使用Switch控件是,默认样式一搬不能满足我们的需求,但是通过一些属性的使用,我们就能得到我们想要的样式。
<Switch android:layout_width="wrap_content" android:layout_height="wrap_content" android:switchMinWidth="35dp" android:showText="true" android:textOn="" android:textOff="" android:thumb="@drawable/switch_thumb" android:track="@drawable/switch_track"/>其中:
switchMinWidth:表示开关最小宽度
showText 表示是否显示textOn和textOff的内容
textOn表示开关打开时的文案
textOff表示开关关闭时的文案
thumb表示开关滑块的图片,可以是selector
track表示开关背景图片,可以是selector
switch_track为:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/blue_track" android:state_checked="true"/> <item android:drawable="@drawable/grey_track"/></selector>
blue_track:
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <size android:height="20dp"/> <corners android:radius="10dp"/> <gradient android:endColor="@color/main_blue" android:startColor="@color/main_blue"/></shape>grey_track:
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <size android:height="20dp"/> <corners android:radius="10dp"/> <gradient android:endColor="@color/main_disable" android:startColor="@color/main_disable"/></shape>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/switch_thumb_checked" android:state_checked="true"/> <item android:drawable="@drawable/switch_thumb_reset"/></selector>switch_thumb_checked:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" android:useLevel="false"> <solid android:color="@color/main_white"/> <stroke android:width="1dp" android:color="@color/main_blue"/> <size android:width="20dp" android:height="20dp"/></shape>switch_thumb_reset:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" android:useLevel="false"> <solid android:color="@color/main_white"/> <stroke android:width="1dp" android:color="@color/main_line"/> <size android:width="20dp" android:height="20dp"/></shape>
如果要修改开关的高度,直接修改track中的height属性即可。
阅读全文
0 0
- 关于Switch控件的使用
- switch控件的使用
- 关于switch语句的使用
- android 4.0 switch控件的使用
- Android 开关控件Switch的简单使用
- switch 语句关于case的使用
- android studio switch控件使用
- iPhone基础开发之switch控件的使用
- Android switch控件的使用,及简单样式改变
- 关于Switch的参数
- 5.4 关于switch的
- 使用Android原生控件自定义Switch控件
- 关于switch。。case的使用中break的重要性
- 关于javaScript switch 使用心得
- 关于java中switch使用的一些说明
- 关于switch语句中使用String类型的实现原理
- 使用switch的注意
- switch函数的使用
- hdu 2639 (Bone Collector II) 0-1背包的第k优解
- NOIP 2002 均分纸牌
- Filter过滤器
- 《大话设计模式》读书笔记之C++实现--chapter22桥接模式
- Gym 101389. B
- 关于Switch控件的使用
- Saltstack安装LAMP
- codeforces 870C. Maximum splitting
- [NOIP2017模拟]玩积木
- 学习uboot前奏之hardware-IRQ[s3c2440]
- 流程控制语句
- Learning Python Part III 之 模块
- 快速使用ConstraintLayout
- CCD/CMOS靶面尺寸型号标准