Change color of android:activatedBackgroundIndicator
Asked Answered
P

2

27

Can I change the default color (blue) of the attr android:activatedBackgroundIndicator?

I am developing an application for target 18 and for minimun 11.

Thank you

Prosaism answered 26/9, 2013 at 20:42 Comment(1)
Are you trying to change this app-wide, or only for one container?Sylph
M
55

Here is a way to change it on your theme:

Update your theme to apply your custom style on the activatedBackgroundIndicator attribute (here the parent theme is Holo Light but you can of course change it):

<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:activatedBackgroundIndicator">@drawable/list_activated_background</item>
    </style>

In your "drawable" resource folder, create the XML file list_activated_background and define your new background indicator, for example:

<?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>

Then just be sure you are calling your custom theme in the manifest file with android:theme="@style/AppTheme" in this case for example.

Mercia answered 27/9, 2013 at 3:9 Comment(0)
D
6

On Lollipop and above, you have the option of setting colorControlActivated in your theme instead:

<style name="AppTheme" parent="@android:style/Theme.Material">
    <item name="colorControlActivated">@color/your_color</item>
</style>

This approach works because the Material Theme's activatedBackgroundIndicator selector uses ?attr/colorControlActivated for the activitate state as seen in themes_material.xml and activated_background_material.xml.

Note that Yoann Hercouet's answer is correct and still works in Lollipop.

Disinfectant answered 30/6, 2015 at 19:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.