Android 高仿IOS打开和关闭按钮
来源:互联网 发布:compareto java用法 编辑:程序博客网 时间:2024/06/15 18:28
一、废话不多说,先上图
二、实现思路
如果你们的效果要求不是太严苛,你可以使用这种方式。看起来还是挺美观和漂亮的。
1、使用系统的Switch控件,然后设置thumb和track背景就能实现
2、然后监听setOnCheckedChangeListener就能知道打开和关闭
三、代码
activity.xml
<Switch android:id="@+id/activity_setServe_switch_open" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textOff="" android:layout_marginTop="100dp" android:layout_marginLeft="100dp" android:textOn="" android:thumb="@drawable/switch_thumb" android:track="@drawable/switch_track" />switch_thumb.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <size android:width="30dp" android:height="30dp"> </size> <solid android:color="@android:color/white"> </solid></shape>
switch_track.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/switch_track_on"/> <item android:state_checked="false" android:drawable="@drawable/switch_track_off"/></selector>
switch_track_off.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#e4e4e4"> </solid> <corners android:radius="30dp"> </corners></shape>switch_track_on.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#00ABEC"> </solid> <corners android:radius="32dp"> </corners></shape>
最后设置监听事件
((Switch)findViewById(R.id.activity_setServe_switch_open)). setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { Toast.makeText(MainActivity.this,"打开",Toast.LENGTH_LONG).show(); } else { Toast.makeText(MainActivity.this,"关闭",Toast.LENGTH_LONG).show(); } } });
阅读全文
0 0
- Android 高仿IOS打开和关闭按钮
- android仿ios开关按钮
- android仿ios开关按钮
- Android高仿IOS和QQ的弹出对话框
- 【Android】仿IOS的滑动按钮
- UISwitch打开,关闭按钮
- android 关闭和打开Speaker
- Android打开和关闭输入法
- Android:打开和关闭输入法
- Android打开和关闭输入法
- Android 打开和关闭扬声器
- android 打开和关闭输入法
- Android 打开和关闭闪光灯
- Android 高仿 IOS 滚轮选择控件
- android高仿ios开关-CheckBox-Button
- Android 高仿IOS底部Dialog对话框。
- Android 高仿 IOS 滚轮选择控件
- iOS 闪光灯的打开和关闭
- I2C驱动情景分析——怎样控制I2C时序
- LCD显示的一些基本概念以及DSI的一些clock解释
- js常用函数和语法笔记
- 使用ViewModel共享页面内的数据:ActivityDataBus
- 10、XPath 学习记录——XPath操作HTML
- Android 高仿IOS打开和关闭按钮
- BZOJ1529 ska Piggy banks [并查集]
- 欢迎使用CSDN-markdown编辑器
- 阿里云Ecs安装的mysql远程连接报错10060
- mysql中对建好的表中添加一列
- UVA 11987 并查集(虚拟节点)
- N皇后问题(回溯算法解法)
- Java 面向对象
- JFinal 验证码绘制