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 ...
随机推荐
- Ubuntu12.04安装JDK(jdk-6u45-linux-x64.bin)(转载)
首先下载jdk-6u45-linux-x64.bin, 如果是32bit系统下载相应的i386即可. 更改文件权限-> chmod a+x jdk-6u45-linux-x64.bin. 创建目 ...
- ACM_走楼梯Ⅱ
走楼梯Ⅱ Time Limit: 2000/1000ms (Java/Others) Problem Description: 有一楼梯共N+1级,刚开始时你在第一级,若每次能走M级(1<=M& ...
- java IO流 之 字节输出流 OutputString()
Java学习重点之一:OutputStream 字节输出流的使用 FileOutPutStream:子类,写出数据的通道 步骤: 1.获取目标文件 2.创建通道(如果原来没有目标文件,则会自动创建一个 ...
- JavaScript 兼容新旧版chrome和firefox的桌面通知
1.新/旧版本的chrome和firefox都可支持,IE下不支持因此设置为了在最小化窗口处闪烁显示提示文字. 2.设置为提示窗口显示5秒即关闭. 3.可设置图标和点击提示窗口要跳转到的页面(见输入参 ...
- PyCharm使用指南及更改Python pip源为国内豆瓣
PyCharm基本使用 1.在PyCharm下为python项目配置python本地解释器 setting-->Project:pycharm workspace-->Project In ...
- viewpager滑动时页面不能刷新
有一种解决方法就是覆盖PagerAdapter中的getItemPosition()方法,这种方案虽然简单,但是因为这种方法是让每次呼叫PagerAdapter时,都会遍历childView,通过ge ...
- Pro ASP.NET Core MVC 第6版 第二章(前半章)
目录 第二章 第一个MVC 应用程序 学习一个软件开发框架的最好方法是跳进他的内部并使用它.在本章,你将用ASP.NET Core MVC创建一个简单的数据登录应用.我将它一步一步地展示,以便你能看清 ...
- HTML5——移动端的点击、拖拽
移动端浏览器不支持mouse事件 https://www.cnblogs.com/joyco773/p/6519668.html https://www.cnblogs.com/yjhua/p/525 ...
- 腾讯云 LNMP+wordpress 搭建个人网站
折腾了好几个小时才弄好(php nginx略知一二),其实一点都不难! 以此记录一下,献给首次搭建的朋友们!! 1)准备工作:(因为个人用的ubuntu16.04 LTS系统 所以这是debian版 ...
- 三维卷积:全景图像Spherical CNNs(Code)
卷积神经网络(CNN)可以很好的处理二维平面图像的问题.然而,对球面图像进行处理需求日益增加.例如,对无人机.机器人.自动驾驶汽车.分子回归问题.全球天气和气候模型的全方位视觉处理问题. 将球形信号的 ...