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的更多相关文章

  1. 自定义的开关按钮——SwitchButton

    本文转自:http://blog.csdn.net/swust_chenpeng/article/details/19967501 我将原文的控件进行了一些修改,去掉了原来控件的外边框,只留下重要的遮 ...

  2. Android 自定义的开关按钮——SwitchButton

    本文转自:http://blog.csdn.net/swust_chenpeng/article/details/19967501 我将原文的控件进行了一些修改,去掉了原来控件的外边框,只留下重要的遮 ...

  3. Android开源项目库汇总

    最近做了一个Android开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个star. 抽 ...

  4. GitHub上受欢迎的Android UI Library

    GitHub上受欢迎的Android UI Library 内容 抽屉菜单 ListView WebView SwitchButton 按钮 点赞按钮 进度条 TabLayout 图标 下拉刷新 Vi ...

  5. Android UI相关开源项目库汇总

    最近做了一个Android UI相关开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个st ...

  6. 最新最全的 Android 开源项目合集

    原文链接:https://github.com/opendigg/awesome-github-android-ui 在 Github 上做了一个很新的 Android 开发相关开源项目汇总,涉及到 ...

  7. SwitchButton 开关按钮 的多种实现方式

    刚开始接触开关样式的按钮是在IOS系统上面,它的切换以及滑动十分帅气,深入人心. 所谓的开关按钮,就是只有2个状态:on和off,下图就是系统IOS 7上开关按钮效果. 起初我在android上我只会 ...

  8. SwitchButton 开关按钮 的多种实现方式 (附源码DEMO)

    http://blog.csdn.net/vipzjyno1/article/details/23707149 Switch开关android源码SwitchButton 刚开始接触开关样式的按钮是在 ...

  9. [C#] (原创)一步一步教你自定义控件——03,SwitchButton(开关按钮)

    一.前言 技术没有先进与落后,只有合适与不合适. 本篇的自定义控件是:开关按钮(SwitchButton). 开关按钮非常简单,实现方式也多种多样,比如常见的:使用两张不同的按钮图片,代表开和关,然后 ...

随机推荐

  1. 单线程和多线程处理1W条数据对比代码

    package study.interview; import java.util.ArrayList; import java.util.HashMap; import java.util.Link ...

  2. C++ 函数特性_函数重载

    函数重载 在相同作用域内 用同一函数名定义的多个函数: 参数个数和参数类型不同 int getMax(int x,int y,int z) // 函数名相同都是 getMax() { // to do ...

  3. 学习笔记之SQL / MySQL

    SQL Fiddle(在线执行SQL语句的网站) http://www.sqlfiddle.com/ MySQL https://www.mysql.com/ MySQL :: MySQL 5.7 R ...

  4. springboot的interceptor(拦截器)的应用

    一.SpringMVC 中的Interceptor 拦截器也是相当重要和相当有用的,它的主要作用是拦截用户的请求并进行相应的处理.在web开发中,拦截器是经常用到的功能.它可以帮我们验证是否登陆.预先 ...

  5. 【UVALive】4094 WonderTeam(神结论)

    题目 传送门:QWQ 分析 好神的结论啊 看代码吧(Length只有85) 代码 顺手压了压代码      目前代码长度rk1 vjudge #include <iostream> ?:n ...

  6. 【UVA】10891 Game of Sum(区间dp)

    题目 传送门:QWQ 分析 大力dp.用$ dp[i][j] $表示$ [i,j] $A能得到的最高分 我看到博弈论就怂... 代码 #include <bits/stdc++.h> us ...

  7. redis for windows之nosql还需要入门?

    RT:nosql给很多人的感觉就是上手特别快,本文也是一篇入门级的,哎~~ 又写了一篇没有卵用的博文,姑且把它当作一篇文档吧,还是没有发布/订阅.事件...等介绍的一篇残缺文档,幸好废话不是很多,凑合 ...

  8. 我对商业模式O2O的理解

    过这个文章不是来吐槽项目经理多麽困难的,而且对商业模式的一点心得和讨论. 在这个公司,从项目建设上讲,老实说贡献不是很大,做项目经理团队带的不好,当然小创业公司本身资源真的非常有限,自己也特别累,有老 ...

  9. Asp.net 中高亮显示搜索关键字简单方法

    今天用到搜索时的高亮显示,百度了一下,如下面: 1.替换关键字,对字体变色.         public static string ReplaceRed(string strtitle, stri ...

  10. hive基本结构与数据存储

    一.Hive简介 Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供类SQL查询功能.还可以将 SQL 语句转换为 MapReduce 任务进行运行,通过自 ...