好用的开关按钮——switchbutton
1.简介
GitHub地址:https://github.com/zcweng/SwitchButton
gradle:
repositories {
mavenCentral()
jcenter()
}
...
dependencies {
compile 'com.github.zcweng:switch-button:0.0.3@aar'
}
2.使用
xml中使用:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"> <com.suke.widget.SwitchButton
android:id="@+id/switch_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/> </LinearLayout>
activity.java:
com.suke.widget.SwitchButton switchButton = (com.suke.widget.SwitchButton)
findViewById(R.id.switch_button); switchButton.setChecked(true);
switchButton.isChecked();
switchButton.toggle(); //switch state
switchButton.toggle(false);//switch without animation
switchButton.setShadowEffect(true);//disable shadow effect
switchButton.setEnabled(false);//disable button
switchButton.setEnableEffect(false);//disable the switch animation
switchButton.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(SwitchButton view, boolean isChecked) {
//TODO do your job
}
});
more style:
<attr name="sb_shadow_radius" format="reference|dimension"/> 阴影半径
<attr name="sb_shadow_offset" format="reference|dimension"/> 阴影偏移
<attr name="sb_shadow_color" format="reference|color"/> 阴影颜色
<attr name="sb_uncheck_color" format="reference|color"/> 关闭颜色
<attr name="sb_checked_color" format="reference|color"/> 开启颜色
<attr name="sb_border_width" format="reference|dimension"/> 边框宽度
<attr name="sb_checkline_color" format="reference|color"/> 开启指示器颜色
<attr name="sb_checkline_width" format="reference|dimension"/> 开启指示器线宽
<attr name="sb_uncheckcircle_color" format="reference|color"/> 关闭指示器颜色
<attr name="sb_uncheckcircle_width" format="reference|dimension"/> 关闭指示器线宽
<attr name="sb_uncheckcircle_radius" format="reference|dimension"/>关闭指示器半径
<attr name="sb_checked" format="reference|boolean"/> 是否选中
<attr name="sb_shadow_effect" format="reference|boolean"/> 是否启用阴影
<attr name="sb_effect_duration" format="reference|integer"/> 动画时间,默认300ms
<attr name="sb_button_color" format="reference|color"/> 按钮颜色
<attr name="sb_show_indicator" format="reference|boolean"/> 是否显示指示器,默认true:显示
<attr name="sb_background" format="reference|color"/> 背景色,默认白色
<attr name="sb_enable_effect" format="reference|boolean"/> 是否启用特效,默认true
也可以直接把SwitchButton.java和switch_btton_attr.xml复制到项目中直接使用
<com.example.switchbuttondemo1.customview.SwitchButton
android:layout_width="100dp"
android:layout_height="50dp"
android:id="@+id/switchbutton"
android:layout_centerInParent="true"
app:sb_shadow_color="#f00"
app:sb_uncheck_color="#0f0"
app:sb_checked_color="#f0f"
app:sb_border_width="3dp"
app:sb_checkline_color="#f00"
app:sb_checkline_width="5dp"
app:sb_uncheckcircle_color="#f00"
app:sb_uncheckcircle_radius="10dp"
app:sb_uncheckcircle_width="2dp"
app:sb_button_color="#0ff"
app:sb_show_indicator="false"
/>
好用的开关按钮——switchbutton的更多相关文章
- 自定义的开关按钮——SwitchButton
本文转自:http://blog.csdn.net/swust_chenpeng/article/details/19967501 我将原文的控件进行了一些修改,去掉了原来控件的外边框,只留下重要的遮 ...
- Android 自定义的开关按钮——SwitchButton
本文转自:http://blog.csdn.net/swust_chenpeng/article/details/19967501 我将原文的控件进行了一些修改,去掉了原来控件的外边框,只留下重要的遮 ...
- Android开源项目库汇总
最近做了一个Android开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个star. 抽 ...
- GitHub上受欢迎的Android UI Library
GitHub上受欢迎的Android UI Library 内容 抽屉菜单 ListView WebView SwitchButton 按钮 点赞按钮 进度条 TabLayout 图标 下拉刷新 Vi ...
- Android UI相关开源项目库汇总
最近做了一个Android UI相关开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个st ...
- 最新最全的 Android 开源项目合集
原文链接:https://github.com/opendigg/awesome-github-android-ui 在 Github 上做了一个很新的 Android 开发相关开源项目汇总,涉及到 ...
- SwitchButton 开关按钮 的多种实现方式
刚开始接触开关样式的按钮是在IOS系统上面,它的切换以及滑动十分帅气,深入人心. 所谓的开关按钮,就是只有2个状态:on和off,下图就是系统IOS 7上开关按钮效果. 起初我在android上我只会 ...
- SwitchButton 开关按钮 的多种实现方式 (附源码DEMO)
http://blog.csdn.net/vipzjyno1/article/details/23707149 Switch开关android源码SwitchButton 刚开始接触开关样式的按钮是在 ...
- [C#] (原创)一步一步教你自定义控件——03,SwitchButton(开关按钮)
一.前言 技术没有先进与落后,只有合适与不合适. 本篇的自定义控件是:开关按钮(SwitchButton). 开关按钮非常简单,实现方式也多种多样,比如常见的:使用两张不同的按钮图片,代表开和关,然后 ...
随机推荐
- web deploy 部署到远程服务器(win server 2008 r2) 遇到的问题。。。。
和他遇到的情况一样,最后也解决了 http://www.cnblogs.com/brucejia/archive/2012/07/30/2615416.html 安装的前提是先看下这里: http:/ ...
- MySQL锁之二:锁相关的配置参数
锁相关的配置参数: mysql> SHOW VARIABLES LIKE '%timeout%'; +-----------------------------+----------+ | Va ...
- Eclipse Android 代码自动提示功能 +导入 epf
1.设置 java 文件的代码提示功能 打 开 Eclipse 依次选择 Window > Preferences > Java > Editor - Content Assist ...
- 学习了django对于sqlite3进行了了解,谈谈看法
学习了django对于sqlite3进行了了解,谈谈看法 由于django默认使用的是sqlite3,写了几个建表语句, 然后数据做下迁移,其实就是建表语句的执行. 一直对sqlite3没有一个直观的 ...
- Timer控件的使用限制和注意事项
Timer的Interval 属性当编写 Timer 组件时,需要考虑 Interval 属性的几点限制:1. 如果应用程序或另一个应用程序对系统需求很大(如长循环.大量的计算或驱动程序.网络或端口访 ...
- zookeeper无故挂掉,启动不起来的问题
一台测试的服务器重启后,运行zookeeperd的启动脚本显示启动成功: [plain] view plain copy JMX enabled by default Using config ...
- LUA 删除元素的问题
table在删除元素时要注意,例t = { "hello", "world", "!"}t[1] = nil此时print(#t) --输出 ...
- Vue-cli webpack模板
Vue webpack项目开始构建模板使用,关键内容摘要 中文文档 https://loulanyijian.github.io/vue-cli-doc-Chinese/ 官方英文 http://vu ...
- MVC各层的职责
Model(模型):模型代表着核心的业务逻辑和数据(不要理解成Model只是实体类) View(视图):视图应该关注与如何展示数据,而不应该包含任何业务逻辑(业务逻辑应写在Model中) Contro ...
- 初步认识session
TestSession01.java protected void doPost(HttpServletRequest request, HttpServletResponse response) t ...