Dav*_*run 2 android button toggle
我正在尝试在Android中构建自定义切换按钮,我希望它看起来像单选按钮但功能为切换按钮.有人可以帮我弄这个吗?任何线索提示接近答案表示赞赏.
Noa*_*oah 10
您需要通过一些自定义xml覆盖切换按钮的外观
快速概述:
在你的布局xml android:background ="@ drawable/round_toggle"/>
在round_toggle.xml中添加具有多个状态(最多6个默认值)的选择器
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/roundtoggle_on_pressed" />
<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/roundtoggle_on_focused" />
<item android:state_checked="true" android:state_focused="false"
android:drawable="@drawable/roundtoggle_on_normal" />
<item android:state_checked="false" android:state_pressed="true"
android:drawable="@drawable/roundtoggle_off_pressed" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/roundtoggle_off_focused" />
<item android:state_checked="false" android:state_focused="false"
android:drawable="@drawable/roundtoggle_off_normal" />
<item android:drawable="@drawable/roundtoggle_off_normal" />
</selector>
Run Code Online (Sandbox Code Playgroud)详情请见http://www.anddev.org/act_custom_togglebuttons-t10620.html
| 归档时间: |
|
| 查看次数: |
12825 次 |
| 最近记录: |