CiD*_*TaR 6 android android-4.0-ice-cream-sandwich
我对Android 4中的切换按钮感到疯狂.
首先,我设置了一个选择器作为背景,从drawable文件夹中选择了两个不同的PNG文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/form_switch_no" android:state_checked="false"/>
<item android:drawable="@drawable/form_switch_ok" android:state_checked="true"/>
<item android:drawable="@drawable/form_switch_no"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
但我不知道为什么他们是x-scaled.我想管理这个大小,但我试图改变layout_width/height/weight ...没有成功.
我还有一个自定义PNG文件用作交换机的拇指.我还需要管理这个拇指的大小,因为如果我将textOn和textOff propments设置为"",拇指的大小就会非常小.此外,我想改变背景的拇指填充,因为它不会出现居中.
这是我的Switch XML定义:
<Switch
android:id="@+id/switchUsers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/user"
android:textOn=""
android:textOff=""
android:thumb="@drawable/form_switch_slider"
android:track="@drawable/switch_user_selector" />
Run Code Online (Sandbox Code Playgroud)
我试图改变图像大小并使它们成为九个补丁,但我无法达到目标.
任何帮助将不胜感激.谢谢!
没有文字的极小滑块的解决方案通过以下组合解决:
android:thumbTextPadding="25dp"
android:textOn=""
android:textOff=""
Run Code Online (Sandbox Code Playgroud)
然后,同一滑块中的小填充问题是9补丁图像问题.我不得不在底部和右边的黑色线上再增加一个像素.
希望这可以帮助有同样问题的人.