更改android:activatedBackgroundIndicator的颜色

Asa*_*asa 27 android colors

我可以更改attr android:activatedBackgroundIndicator的默认颜色(蓝色)吗?

我正在开发目标18和最小11的应用程序.

谢谢

Yoa*_*uet 55

这是一种在主题上更改它的方法:

更新主题以在activatedBackgroundIndicator属性上应用自定义样式(此处父主题为Holo Light,但您当然可以更改它):

<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:activatedBackgroundIndicator">@drawable/list_activated_background</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

在"drawable"资源文件夹中,创建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>
Run Code Online (Sandbox Code Playgroud)

然后确保您在清单文件中调用自定义主题,android:theme="@style/AppTheme"例如在这种情况下.


Joh*_*ngs 6

在Lollipop及以上版本中,您可以选择colorControlActivated在主题中进行设置:

<style name="AppTheme" parent="@android:style/Theme.Material">
    <item name="colorControlActivated">@color/your_color</item>
</style>
Run Code Online (Sandbox Code Playgroud)

这种方法有效,因为Material Theme的activatedBackgroundIndicator选择器?attr/colorControlActivated用于activics状态,如themes_material.xmlactivated_background_material.xml中所示.

请注意,Yoann Hercouet的答案是正确的,仍然适用于棒棒糖.