Android第三方开源SwitchButton
来源:互联网 发布:matlab元胞转化为矩阵 编辑:程序博客网 时间:2024/06/11 10:28
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初学-----SwitchButton
- Android SwitchButton 开关按钮
- Android CheckBox实现SwitchButton
- android中实现switchButton
- switchbutton
- switchButton
- SwitchButton
- SwitchButton
- Android SwitchButton(滑动开关)
- Android SwitchButton(滑动开关)
- android 自定义开关(SwitchButton)
- Android SwitchButton(滑动开关)
- Android View 仿iOS SwitchButton
- Android 自定义SwitchButton开关控件
- Android 仿iOS 开关SwitchButton
- Android 与 SwitchButton亲密约会《-》
- Android SwitchButton(滑动开关)
- LcLableView 轻松添加 热门 最新 等标签
- Unsupported major.minor version 51.0问题及解决方法
- Transforms动画汇总
- jsp页面动态展示list-使用<select>和<c:forEach>标签
- java的ExecutorService线程池的使用
- Android第三方开源SwitchButton
- 《Spring实战》学习笔记-第三章:最小化SpringXML配置
- Swing图形绘制(长方形、椭圆、同心圆及直方图)
- 数组类型转换
- javascript里的sleep()方法
- broadleaf电商文档翻译 Merge Configuration 合并配置
- Java线上应用故障排查之一:高CPU占用
- HP Gen8系列服务器硬盘超过2T的分区方法
- elasticsearch清空索引缓存 java api