【发布时间】:2013-10-03 00:24:10
【问题描述】:
我可以更改 attr android:activatedBackgroundIndicator 的默认颜色(蓝色)吗?
我正在为 target 18 和 minimun 11 开发一个应用程序。
谢谢
【问题讨论】:
-
您是要在整个应用程序范围内更改此应用程序,还是只更改一个容器?
我可以更改 attr android:activatedBackgroundIndicator 的默认颜色(蓝色)吗?
我正在为 target 18 和 minimun 11 开发一个应用程序。
谢谢
【问题讨论】:
在 Lollipop 及更高版本上,您可以选择在主题中设置 colorControlActivated:
<style name="AppTheme" parent="@android:style/Theme.Material">
<item name="colorControlActivated">@color/your_color</item>
</style>
这种方法之所以有效,是因为 Material Theme 的 activatedBackgroundIndicator 选择器使用 ?attr/colorControlActivated 作为激活状态,如 themes_material.xml 和 activated_background_material.xml 所示。
请注意,Yoann Hercouet 的回答是正确的,并且在 Lollipop 中仍然有效。
【讨论】:
这是一种在您的主题上更改它的方法:
更新您的主题以在 activatedBackgroundIndicator 属性上应用您的自定义样式(这里的父主题是 Holo Light,但您当然可以更改它):
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:activatedBackgroundIndicator">@drawable/list_activated_background</item>
</style>
在“可绘制”资源文件夹中,创建 XML 文件 list_activated_background 并定义新的背景指示器,例如:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:drawable="@color/OrangeLight" />
<item android:state_checked="true" android:drawable="@color/OrangeDark" />
<item android:state_pressed="true" android:drawable="@color/OrangeDark" />
<item android:drawable="@android:color/transparent" />
</selector>
然后,请确保您在清单文件中使用 android:theme="@style/AppTheme" 调用您的自定义主题,例如在这种情况下。
【讨论】: