ActionMode with AppCompat can't change background and text colors

1.1k views Asked by At

I'm trying to change the background and text colors for my ActionMode. I'm using API 11 and AppCompat.

I've tried it with the following style.xml, but the ActionMode background is always white and the text color is black. I want to change text color to white and background color to blue.

How can I solve this?

Here is my style.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- ActionMode -->
        <item name="actionModeStyle">@style/MyActionModeStyle</item>
    </style>


    <!-- Setup the style of the ActionMode here -->
    <style name="MyActionModeStyle" parent="@style/Widget.AppCompat.ActionMode">
        <item name="android:background">@color/blue</item>
        <item name="background">@color/blue</item>
        <item name="android:titleTextStyle">@style/MyActionModeTitle</item>

        <item name="titleTextStyle">@style/MyActionModeTitle</item>
    </style>

    <!-- Setup the text style of the ActionMode here -->
    <style name="MyActionModeTitle" parent="@style/TextAppearance.AppCompat.Widget.ActionMode.Title">
        <item name="android:textColor">#ffffff</item>
    </style>
</resources>

In my Activity I'm using android.support.v7.app.ActionBarActivity but I use toolbar: Here is my settings_activity_toolbar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    app:navigationContentDescription="@string/abc_action_bar_up_description"
    android:background="?attr/colorPrimary"
    app:navigationIcon="?attr/homeAsUpIndicator"
    app:title="@string/action_settings" />
2

There are 2 answers

0
Tobi On

Ok, I managed it by replacing the HomeAsUpIndicator programatically with an done button. Thats all I wanted...

1
Simas On

Try to set android:actionModeStyle too:

<item name="android:actionModeStyle">@style/MyActionModeStyle</item>