Android第三方开源SwitchButton
Android第三方开源SwitchButton
Android SwitchButton是github上的一个第三方开源项目,其项目主页是:https://github.com/kyleduo/SwitchButton
Android平台上的Switch Button样式单一,SwitchButton旨在丰富Android平台的Switch样式的Button,其实现的结果如图:
注意到SwitchButton其中一个实现,就是iOS样式的Switch切换开关。
SwitchButton本身给出实例代码结构不是很简单直观,我把其中关于iOS的SwitchButton实现,抽取出来单独写一个例子结果如图:
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="zhangphil.demo.MainActivity"> <com.kyleduo.switchbutton.SwitchButton
android:id="@+id/switchButton"
style="@style/SwitchButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:checked="false"
app:kswAnimationDuration="300"
app:kswBackDrawable="@drawable/ios_back_drawable"
app:kswBackMeasureRatio="1.4"
app:kswThumbDrawable="@drawable/ios_thumb_selector"
app:kswThumbMarginBottom="-8dp"
app:kswThumbMarginLeft="-5dp"
app:kswThumbMarginRight="-5dp"
app:kswThumbMarginTop="-2.5dp" /> </RelativeLayout>
上层Java代码:
package zhangphil.demo; import android.app.Activity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Toast; import com.kyleduo.switchbutton.SwitchButton; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); SwitchButton mSwitchButton = (SwitchButton) findViewById(R.id.switchButton);
mSwitchButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
String s;
if (b)
s = "选中";
else
s = "未选"; Toast.makeText(getApplication(), s, Toast.LENGTH_SHORT).show();
}
});
}
}
我写的这个例子已经push到github上,该代码的项目主页是:https://github.com/zhangphil/Android_iOS_SwitchButton
附录文章:
1,《Android Segmented RadioButton》链接地址:http://blog.csdn.net/zhangphil/article/details/51441677
2,《Android选项切换条SHSegmentControl》链接地址:http://blog.csdn.net/zhangphil/article/details/49720805
3,《Android ToggleButton:状态切换的Button》链接地址:http://blog.csdn.net/zhangphil/article/details/51720565
Android第三方开源SwitchButton的更多相关文章
- Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)
Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog) Android第三方开源对话消息提示框:SweetAlertDialog(sweet- ...
- Android第三方开源SeekBarCompat:音乐类播放器等APP进度条常用
Android第三方开源SeekBarCompat:音乐类播放器等APP进度条常用 Android平台原生的SeekBar设计简单,然而,比如现在流行的一些音乐播放器的播放进度控制条,如果直接使 ...
- Android第三方开源图片裁剪截取:cropper
Android第三方开源图片裁剪截取:cropper 很多app都需要裁剪截取图片作为头像.logo之类,而cropper是github上的一个针对Android平台的.第三方开源图片裁剪截取项 ...
- Android第三方开源下拉框:NiceSpinner
Android第三方开源下拉框:NiceSpinner Android原生的下拉框Spinner基本上可以满足Android开发对于下拉选项的设计需求,但现在越来越流行的下拉框不满足于Andro ...
- Android 第三方开源下拉框:NiceSpinner
Android原生的下拉框Spinner基本上可以满足Android开发对于下拉选项的设计需求,但现在越来越流行的下拉框不满足于Android原生提供的下拉框Spinner所提供的设计样式,而改用自定 ...
- Android 第三方开源库收集整理(转)
原文地址:http://blog.csdn.net/caoyouxing/article/details/42418591 Android开源库 自己一直很喜欢Android开发,就如博客签名一样, ...
- 45.Android 第三方开源库收集整理(转)
原文地址:http://blog.csdn.net/caoyouxing/article/details/42418591 Android开源库 自己一直很喜欢Android开发,就如博客签名一样, ...
- 030 Android 第三方开源下拉框:NiceSpinner的使用+自定义Button样式+shape绘制控件背景图+图片选择器(selector)
1.NiceSpinner下拉框控件介绍 Android原生的下拉框Spinner基本上可以满足Android开发对于下拉选项的设计需求,但现在越来越流行的下拉框不满足于Android原生提供的下拉框 ...
- 【我的Android进阶之旅】如何快速寻找Android第三方开源库在Jcenter上的最新版本
问题描述 解决方法 先了解compile comsquareupokhttpokhttp240的意义 了解Jcenter和Maven jcenter Maven Central 理解jcenter和M ...
随机推荐
- ubuntu中 python升级 (转载)
转自:http://blog.csdn.net/menglin8908/article/details/16822171 在ubuntu12.04中内置的python版本为2.7.3,最近想把pyth ...
- 第三章 K近邻法(k-nearest neighbor)
书中存在的一些疑问 kd树的实现过程中,为何选择的切分坐标轴要不断变换?公式如:x(l)=j(modk)+1.有什么好处呢?优点在哪?还有的实现是通过选取方差最大的维度作为划分坐标轴,有何区别? 第一 ...
- 制作并发布个人CocoaPods库
随着对 CocoaPods 越来越多的依赖,我们也可以尝试把自己的库发布到它上面. 1.在Github上新建一个项目(名字我随便取了一个,其他步骤截图为WCUIKit).自己做相应修改即可. 2.克隆 ...
- [ZJOI2008]杀蚂蚁
题意翻译 注意在(0,0)已经有蚂蚁的时候是不会生成新蚂蚁的 还有如果有蚂蚁扛着蛋糕,但是不在某个炮的范围内,炮仍然会打最近的蚂蚁 题目描述 最近,佳佳迷上了一款好玩的小游戏:antbuster. 游 ...
- 为什么,博主我要写下这一系列windows实用网络?
发现,随着自身一路过来所学,无论在大数据领域.还是linux or windows里,菜鸟的我慢慢在长大.把自己比作一个园,面积虽在增加,涉及面增多,但圆外的东西,还是那么多. 现在,正值在校读研 ...
- sql server 行转列 要注意的问题 pivot
select * from ( select mvqr.VoteQuestionId,mvqr.AnswerSolution from JY_MemberVoteQuestionRef as ...
- [ TJOI 2007 ] 线段
\(\\\) \(Description\) 一个\(N\times N\) 的网格,每行有一段要必走,求从\((1,1)\)到\((N,N)\)的最短路长度. \(N\le 2\times10^4\ ...
- 类支付宝密码输入框NumberEditText(简单粗暴的定制方式)
因为项目需要,设计了一个下图样的验证码输入框(ps:个人认为还不如直接一个EditText,用户友好度可能更好,何况这页面99.9%的用户不会使用,但是没办法,别人才是专业的设计师). 其实界面很简单 ...
- mongo 3.4分片集群系列之七:配置数据库管理
这个系列大致想跟大家分享以下篇章: 1.mongo 3.4分片集群系列之一:浅谈分片集群 2.mongo 3.4分片集群系列之二:搭建分片集群--哈希分片 3.mongo 3.4分片集群系列之三:搭建 ...
- struts2特殊符号替换
今天用struts2做了一个小例子,结果发现个问题 action代码如下 private String table; public String execute(){ setName("pe ...