一个简单的自定义SwitchButton
2016-06-06 10:43
525 查看
一个简单的自定义Switchbutton
xml中定义:<Switch style="@style/widget_gender_switch" android:layout_width="110dp" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:checked="false" android:paddingLeft="10dp" android:paddingRight="10dp" android:showText="true" android:textColor="@drawable/switch_text" android:textOff="关" android:textOn="开" android:id="@+id/switch_resume"/>
style定义:
<style name="widget_gender_switch"> <item name="android:switchTextAppearance">@style/Sw</item> <!-- 此设置不需要文字,只显示背景图的开关 --> <item name="android:thumb">@drawable/widget_gender_thumb</item> <!--滑块格式9.png --> <item name="android:thumbTextPadding">20dp</item> <item name="android:track">@drawable/widget_gender_track</item> <!-- 背景图的开关 格式9.png--> </style> <style name="Sw" parent="@android:style/TextAppearance.Holo.Small"> <!-- Switch thumb asset presents a dark background. --> <item name="android:textColor">#fff</item> </style>
效果图:
style定义Sw 中 一定要继承@android:style/TextAppearance.Holo.Small
否则字的颜色显示可能存在一定问题,在某些设备上可能颜色会是黑色.
相关文章推荐
- PHP8新特性之match表达式
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件