android stop按钮,GitHub - panpf/switch-button: SwitchButton 是 Android 上的一个开关按钮控件 【Deprecated】【Stop mai...

logo.png SwitchButton

【Deprecated】【Stop maintenance】停止维护了,推荐使用:https://github.com/zcweng/SwitchButton

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f416e64726f6964253230417273656e616c2d537769746368427574746f6e2d677265656e2e7376673f7374796c653d74727565

SwitchButton 是 Android 上的一个开关按钮控件

aeb1df592fd065657a18231c09f264e4.gif

示例 APP

特性

支持滑动切换

支持标题

支持 Left、Top、Right、Bottom Drawable

支持使用遮罩实现圆角按钮

使用指南

在布局中使用

android:id="@+id/switch"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="接受推送"/>

在代码中使用

SwitchButton 继承自 CompoundButton ,因此你可以像使用 CheckBox 那样设置状态和监听

一些可用的方法:

setDrawables(Drawable, Drawable, Drawable, Drawable):设置图片

setDrawableResIds(int, int, int, int):设置图片ID

setWithTextInterval(int):设置标题和按钮的间距,默认为 16dp

setDuration(int):设置动画持续时间,单位毫秒,默认为 200

setMinChangeDistanceScale(float):设置滑动有效距离比例,默认为 0.2。例如按钮宽度为 100,比例为 0.2,那么只有当滑动距离大于等于 (100*0.2) 才会切换状态,否则就回滚

自定义图片资源

SwitchButton 由四张图片构成

frameDrawable:框架图片,决定按钮的大小以及显示区域

stateDrawable:状态图片,显示开启或关闭状态

stateMaskDrawable:状态图片遮罩层,用于让状态图片按照遮罩层的形状显示

sliderDrawable:滑块图片

第一种方式你可以通过 SwitchButton 的自定义属性设置资源图片,如下:

xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/switch"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="接受推送"

app:frameDrawable="@drawable/switch_frame"

app:stateDrawable="@drawable/selector_switch_state"

app:stateMaskDrawable="@drawable/switch_state_mask"

app:sliderDrawable="@drawable/selector_switch_slider"/>

第二种方式是通过上面提到的 setDrawables(Drawable, Drawable, Drawable, Drawable) 或 setDrawableResIds(int, int, int, int) 方法设置资源图片

License

Copyright (C) 2017 Peng fei Pan

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值