【发布时间】:2014-02-12 16:54:31
【问题描述】:
我正在尝试更改 Android 中开关的颜色。我意识到我需要新的 9 补丁。我去了http://android-holo-colors.com/ 并选择了我的颜色并选择了(切换果冻豆)。要使用 Switch Jelly Bean,我必须使用:https://github.com/BoD/android-switch-backport。要将其导入我的项目,我必须添加:
<item name="switchStyle">@style/Widget.Holo.CompoundButton.Switch</item>
到我的样式,然后在 xml 中我必须像这样使用开关:
<org.jraf.android.backport.switchwidget.Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
现在所有的开关都可以正常工作了。接下来,我将 android holo 颜色生成器输出的所有内容放入适当的文件中:
- 可绘制(2 个选择器文件)
- drawable-hdpi(9个补丁文件)
- drawable-xhdpi(9个补丁文件)
- drawable-xxhdpi(9个补丁文件)
然后我添加到我的 xml 中:
<org.jraf.android.backport.switchwidget.Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumb="@drawable/apptheme_switch_inner_holo_light"
android:track="@drawable/apptheme_switch_track_holo_light" />
但它仍然是原来的蓝色。我相信我做的一切都是正确的。一切都编译(xml,java)。注意:我也在我的 java 中导入org.jraf.android.backport.switchwidget.Switch。有什么想法吗?
【问题讨论】:
-
看看这个帖子,解释的很好[android中的样式开关][1][1]:stackoverflow.com/questions/10118050/…
-
我已经看过了。 Android 全息颜色生成正确的 9 个补丁图像和 2 个可绘制选择器文件,它们肯定在其中,但没有显示出来。
标签: java android xml android-theme android-styles