我想知道如何更改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. 更改UITableView删除图像开关
- 2. 使用开关更改按钮图像
- 3. Android listview setOnItemClickListener通过开关按位置更改图像背景
- 4. 更改Android开关状态
- 5. 使用jQuery开关更改输入更改图像
- 6. Android:从PureData更改图像
- 7. 更改关卡图标的图像源
- 8. 如何更改Android中开关的textcolor
- 9. Android更改图像和文本在列表中查看按位置与开关
- 10. 用开关盒改变图像JavaScript
- 11. Android:更改图像滑动视图
- 12. Android自定义图像开/关按钮
- 13. 的Android NAD动画开关图像
- 14. gwt CellTree更改打开/关闭项目图像动态
- 15. 更改图像(打开和关闭)菜单按钮
- 16. 根据开关状态更改图像以加载
- 17. 当图像传送带开关动态范围文本更改
- 18. Android在更改图像时更改了像素的颜色
- 19. 试图通过开关更改img src
- 20. 展开后图像未更改
- 21. 更改“,”开“”。“在android
- 22. 更改图像SRC图像
- 23. 更改图像
- 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) –