Android Switch Widget: Setting android:track causes thumb and track to not show up
我无法自定义 Android Switch 小部件的外观。我有自定义 xml 可绘制对象,我想将其用于拇指(通常显示”开”或”关”的小按钮部分)和Rails(拇指滑过的背景)。当我使用 android:thumb 设置拇指时,它工作正常。当我设置Rails时(无论是否设置了拇指),开关完全消失,我只剩下文本显示。
这是我只应用拇指时的代码:
1
2 3 4 5 6 7 8 9 |
<com.blahblahblah.blah.CustomSwitch
android:id=“@+id/switch_1” android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:textOff=“Off” android:textOn=“On” android:text=“Something Awesome” android:textColor=“@android:color/black” android:thumb=“@drawable/custom_switch_thumb” /> |
这是预览窗口中的样子:
并且应用了Rails:
1
2 3 4 5 6 7 8 9 |
<com.blahblahblah.blah.CustomSwitch
android:id=“@+id/switch_1” android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:textOff=“Off” android:textOn=“On” android:text=“Something Awesome” android:textColor=“@android:color/black” android:track=“@color/track_color” /> |
应用曲目的预览窗口:
来源:https://www.codenong.com/18659446/