Change color of android:activatedBackgroundIndicator

前端 未结 2 1841
醉梦人生
醉梦人生 2021-01-31 09:25

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 yo

相关标签:
2条回答
  • 2021-01-31 09:58

    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.

    0 讨论(0)
  • 2021-01-31 10:09

    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.

    0 讨论(0)
提交回复
热议问题