Richard
Richard

Reputation: 14635

Toolbar ActionMode background pre Lollipop does not work

Toolbar ActionMode seems to ignore my style on devices pre Lollipop.

Here is my style:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <!--We will be using the toolbar so no need to show ActionBar-->
    <item name="windowActionBar">false</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="windowActionModeOverlay">true</item>

    <item name="android:textColorPrimary">#DD000000</item>
    <item name="android:textColorSecondary">#8A000000</item>
    <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
    <!-- colorPrimary is used for the default action bar background -->

    <!-- Set AppCompat’s color theming attrs -->
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/secondary</item>

    <item name="colorAccent">@color/accent</item>

    <item name="android:actionModeStyle">@style/Widget.ActionMode</item>
    <item name="android:actionModeBackground">@drawable/toolbar_action_background</item>
    <item name="android:actionModeCloseDrawable">@drawable/ic_arrow_back_white_24dp</item>

</style>

<style name="Widget.ActionMode" parent="@style/Widget.AppCompat.ActionMode">
    <item name="android:background">@drawable/toolbar_action_background</item>
    <item name="android:titleTextStyle">@style/TitleTextStyle</item>

</style>

<style name="TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">#fff</item>
</style>

And my toolbar xml

<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"
    android:elevation="4dp"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    android:background="?attr/colorPrimary" />

I've checked these questions: How to specify dark action mode with my theme Toolbar and Contextual ActionBar with AppCompat-v7 Unable to style action mode when using Toolbar

Expected behaviour, works fine on lollipop:

enter image description here

How it looks on kitkat:

enter image description here

Upvotes: 4

Views: 2439

Answers (2)

Richard
Richard

Reputation: 14635

Solved by specifying booth android namspace and without in my theme:

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

<style name="ActionMode" parent="Widget.AppCompat.ActionMode">
        <item name="android:background">@drawable/toolbar_action_background</item>
        <item name="background">@drawable/toolbar_action_background</item>
    </style>

Upvotes: 10

SilentKnight
SilentKnight

Reputation: 14021

Look at your Toolbar's theme:

app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

The first style, you didn't give a name. You missed some lines. Then, let's suppose the style which has no name, its name is ToolbarStyle which has a line of <item name="colorPrimary">@color/primary</item> which does matter. Then at your Toolbar layout, replace your app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" by app:theme="@style/ToolbarStyle". Then <item name="colorPrimary">@color/primary</item> will color your Toolbar's background. Are we clear now?

Upvotes: 0

Related Questions