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. sql之强制索引

    1.今天我遇到一个问题,在处理百万级数据查询的时候,一般查询会很慢. 2.第一时间想到是建立联合索引,但是数据库存在多条索引的情况下,索引的执行是全部执行. 3.所以这里要按照特定的索引执行,就必须使 ...

  2. 【BZOJ】1756: Vijos1083 小白逛公园(线段树)

    题目 传送门:QWQ 分析 线段树维护一下最大子序列 维护一下最大前缀 最大后缀  区间和 就ok了 好像只能用结构体..... 代码 #include <bits/stdc++.h> u ...

  3. SPM——How to use github

    In this semester, we take a class called 'Software Project Management'. And in this class, we have l ...

  4. SQL常用条件操作符

    1.SQL的六类内容: (1)数据定义语言(DDL): 创建.删除表结构的语句,包括Create.Drop (2)数据控制语言(DCL): 为定义数据访问及修改权限而实现的语句,包括Grant.Rev ...

  5. #用openfiledialog文件和savefileDialog打开和保存文件

    一.打开文件 Stream myStream = null;            OpenFileDialog openFileDialog1 = new OpenFileDialog();     ...

  6. XGBoost参数调优

    XGBoost参数调优 http://blog.csdn.net/hhy518518/article/details/54988024 摘要: 转载:http://blog.csdn.NET/han_ ...

  7. 【Git】二、安装配置

    一.Git安装 Linux $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \ libz-dev libssl-dev $ ap ...

  8. node.js中的匿名函数, 回调函数和嵌套函数

    定义一个函数相信大家已经很熟悉了, 在javascript里的函数也是非常重要的, 使用率非常高, 有几种函数不是很好理解 一, 匿名函数 var remove = function(num1) { ...

  9. SpringBoot配置Shiro时@RequiresRoles不起作用

    在SpringBoot中配置Shiro,结果@RequiresRoles.@RequiresPermissions等注解都无效 解决方法: 在ShiroConfiguration中注入开启支持aop. ...

  10. Linux基石【第二篇】虚拟网络三种连接方式(转载)

    在虚拟机上安装完Centos系统后,开始配置静态IP,以方便在本宿主机上可以访问虚拟机,在曲折的配置中,了解到虚拟机还有三种连接方式:Bridged,NAT和Host-only,于是,我又一轮新的各种 ...