Android开发开关基本上用不上原生的样式,都要自己改,
空余时间自定义修改了switchButton,用法和原生switchButton一致,可以更换背景图以及开关圆点
支持按住开关随手势左右滑动进行开关控制,动画流畅,
使用也比较简单,
用法:
<com.yangfan.widget.SwitchButton android:id="@+id/pushset_switch2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="50dp" android:layout_centerHorizontal="true" yangfan:bmHeight="45dp" yangfan:bmWidth="80dp"/> <com.yangfan.widget.SwitchButton android:id="@+id/pushset_switch3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="150dp" android:layout_centerHorizontal="true" yangfan:bmHeight="23dp" yangfan:bmWidth="43dp"/>
<com.yangfan.widget.SwitchButton android:id="@+id/pushset_switch1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" yangfan:onDrawable="@mipmap/select_out" yangfan:offDrawable="@mipmap/unselect_out" yangfan:thumbDrawableN="@mipmap/select_in" yangfan:thumbDrawableP="@mipmap/unselect_inside" yangfan:bmHeight="45dp" yangfan:bmWidth="80dp"/>
如果想更换样式,用第三种方式
thumbdrawableN属性为设置按钮松开手的圆点标志
thumbdrawableP属性为设置按钮在触摸状态的圆点标志
onDrawable属性为设置按钮在打开状态的背景图
offDrawable属性为设置按钮在关闭状态的背景图
扫描二维码关注公众号,回复:
2209473 查看本文章
第三种样式效果为:
最后完整效果展示,按下抬起效果,随手势左右滑动操作,使用方法监听等同switchButton一致
How to
To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
在项目根目录的gradle添加
maven {
url 'https://jitpack.io'
}
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
在APP下的gradle添加依赖
compile('com.github.yangfanCode:SwitchButton:V1.0.0') { exclude group: 'com.android.support' }
遇到什么问题欢迎讨论