Search code examples
androidandroid-stylesandroid-actionmode

Having trouble changing the ActionMode background color in Android


My ActionMode menu is showing up as plain white and I don't know why. I have an ActionMode menu.xml which simply has a delete option:

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@+id/action_delete"
          android:title="Delete"
          android:icon="@android:drawable/ic_menu_delete"/>

</menu>

and I have a theme applied to my whole app, defined in styles.xml:

<resources>

    <!-- Base application theme -->
    <style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/paletteLightBlue3</item>
        <item name="colorPrimaryDark">@color/dark_grey</item>
        <item name="colorAccent">@color/paletteLightBlue</item>
        <item name="android:actionModeStyle">@style/aModeBg</item>
    </style>

    <style name="aModeBg" parent="@style/Widget.AppCompat.ActionMode">
        <item name="android:actionModeBackground">@color/dark_red</item>
    </style>

</resources>

As you can see, I've tried setting the actionModeBackground property to dark red, but it still just shows up as white. Can anyone help? Thanks.


Solution

  • OK so I solved this by simply doing this:

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/paletteLightBlue3</item>
        <item name="colorPrimaryDark">@color/dark_grey</item>
        <item name="colorAccent">@color/paletteLightBlue</item>
        <item name="android:actionModeBackground">@color/dark_red</item>
    </style>
    

    I just put set the actionModeBackground in my AppTheme, instead of a separate style. Simple.