我想知道如何更改android中的开关图像。我知道我们可以定制开关并更改颜色等,但我们如何使用另一个图像作为开关。我尝试从我的绘图设置背景,但开关仍然可见并出现在我的图像上。我明白,我们可以使用切换按钮或图像按钮,但我很好奇,如果我们可以这样做到开关。Android更改开关图像
1
A
回答
1
覆盖Switch组件中的android:thumb和android:track以覆盖切换图像和背景色。 对于例如:
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumb="@drawable/drawable_switch"
android:track="@drawable/drawable_bg" />
其中drawable_switch和drawable_bg分别是选择器。
drawable_switch.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/switch_disabled" />
<item android:state_pressed="true" android:drawable="@drawable/switch_pressed" />
<item android:state_checked="true" android:drawable="@drawable/switch_enabled" />
<item android:drawable="@drawable/switch_default" />
drawable_bg.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/switch_bg_disabled" />
<item android:state_focused="true" android:drawable="@drawable/switch_bg_focused" />
<item android:drawable="@drawable/switch_bg_default" />
@Jerry试试这个和恢复,如果你还有其他问题
+0
谢谢!这对我有用。 – JerryKo
0
还有android:thumb
属性。
相关问题
- 1. 使用开关更改按钮图像
- 2. 更改UITableView删除图像开关
- 3. Android listview setOnItemClickListener通过开关按位置更改图像背景
- 4. 更改Android开关状态
- 5. 使用jQuery开关更改输入更改图像
- 6. Android:从PureData更改图像
- 7. Android更改图像和文本在列表中查看按位置与开关
- 8. 用开关盒改变图像JavaScript
- 9. Android在更改图像时更改了像素的颜色
- 10. 的Android NAD动画开关图像
- 11. Android自定义图像开/关按钮
- 12. 根据开关状态更改图像以加载
- 13. 更改“,”开“”。“在android
- 14. 更改图像
- 15. Android开/关视图
- 16. Android:快速更改图像(如动画)
- 17. Android java更改可绘制图像
- 18. Android:如何更改图像的色调?
- 19. 在android上的translateanimation上更改图像
- 20. 如何更改Android上的ImageView图像
- 21. 更改android中的按钮图像
- 22. Android翻转ImageView和更改图像
- 23. 更改Android线程上的图像
- 24. 在Android动画期间更改图像
- 25. 更改Android活动的背景图像
- 26. Android - 更改位图的像素颜色
- 27. 点击时更改背景图像 - Android
- 28. 更改图像的颜色android
- 29. 更改图像视图ANDROID中的图像
- 30. 在Android中更改图像按钮与图库图像
可能duplica te [如何自定义切换按钮?](http://stackoverflow.com/questions/23358822/how-to-custom-switch-button) – Beloo
试试这个[回复](http://stackoverflow.com/questions/ 28981164/android-switch-change-background-of-switch-on-off/28981942#28981942) –