好用的开关按钮——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). 开关按钮非常简单,实现方式也多种多样,比如常见的:使用两张不同的按钮图片,代表开和关,然后 ...
随机推荐
- 黄聪:VS2010编辑C#未启动,打开设计视图时报"未将对象引用设置到对象的实例"
通常情况下,若是你将用户控件写好了放入窗体中,若是有不合理的代码,则会弹出错误提示框,不让你放.若是你之前只是随便加了一个用户控件,并且没有什么问题,但后来你又把控件改坏掉了,那么你打开就会报错(在窗 ...
- RecordingOptions录制设置选项
1.录制思考时间 2.录制方式 3.自定义证书 4.非资源选项
- Linux 性能分析的前 60 秒
编译自:http://techblog.netflix.com/2015/11/linux-performance-analysis-in-60s.html作者: Brendan Gregg转载自:h ...
- Thymeleaf系列五 迭代,if,switch语法
1. 概述 这里介绍thymeleaf的编程语法,本节主要包括如下内容 迭代语法:th:each; iteration status 条件语法:th:if; th:unless switch语法: ...
- Python算法应用实战之队列详解
队列是一种先进先出(First-In-First-Out,FIFO)的数据结构.队列被用在很多地方,比如提交操作系统执行的一系列进程.打印任务池等,一些仿真系统用队列来模拟银行或杂货店里排队的顾客.下 ...
- python beautifulsoup爬虫
爬虫这个听起来很 hack 的名字,是我学习 python 的诱因.当 python 基础学习到一定程度(基本语法,数据类型掌握) 就可以开启自己的小爬虫了.毕竟实践才是提高的最快途径.废话说完了,下 ...
- Redis Windows环境安装
1.下载Windows 版本 Redis: https://github.com/ServiceStack/redis-windows 2. 解压文件: F:\开源代码学习\01_Redis 打开 目 ...
- jeesite快速开发平台(五)----用户-角色-部门-区域-菜单-权限表关系
转自: https://blog.csdn.net/u011781521/article/details/78994904
- node express+mysql搭建简易API服务—body-parser中间件
最近用express搭建了一个简单的RESTful风格的API服务,数据库使用mysql,主要用于获取数据库数据,模糊搜索等. 需要用到的模块: express:这个都很熟悉了: body-parse ...
- 少走弯路,给Java 1~5 年程序员的建议
参考:https://www.jianshu.com/p/5681a1f0aad6 今天LZ是打算来点干货,因此咱们就不说一些学习方法和技巧了,直接来谈每个阶段要学习的内容甚至是一些书籍.这一部分的内 ...