Kalyaganov Alexey
Kalyaganov Alexey

Reputation: 1771

Android ActionMode title background color

I`m using new android support library 21.0.2 and when i call ActionMode for text selection i got this.

Bug or feature

It seems than title textview background is transparent.

Redefining titleTextStyle of ActionMode has no effect.

Any suggestions? Thanks.

theme.xml

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

    <style name="ActionMode" parent="@style/Widget.AppCompat.ActionMode">
        <item name="titleTextStyle">@style/ActionModeTitleTextStyle</item>
    </style>

    <style name="ActionModeTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionMode.Title">
        <item name="android:background">#ff0000</item>
        <item name="android:colorBackground">#ff0000</item>
    </style>

Upvotes: 9

Views: 2226

Answers (2)

Ray Hunter
Ray Hunter

Reputation: 15557

I ran into this issue using the the AppBarLayout with the Toolbar and TabLayout. I had set the background color on the Toolbar and that caused the ActionMode title to display the background color of the Toolbar and not the actionModeBackground color that was set on the Theme.

I moved the background color to the AppBarLayout instead and this fixed the issue with the title having the background color of the Toolbar.

Hope this helps someone!

Upvotes: 5

Sandro Simas
Sandro Simas

Reputation: 1307

This problem happened here even when i upgraded to 22.2.0.
I solved adding items without "android:" prefix to styles and adding style attribute in Toolbar element.

<android.support.v7.widget.Toolbar
  xmlns:android="http://schemas.android.com/apk/res/android"
  style="@style/ToolbarTheme"
  android:id="@+id/toolbar"
  android:layout_width="match_parent"
  android:layout_height="?attr/actionBarSize"
  android:elevation="6dp"/>  

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@color/window_background</item>
    <item name="android:windowActionBar">false</item>

    <item name="android:windowActionModeOverlay">true</item>
    <item name="windowActionModeOverlay">true</item>

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

<style name="AppTheme" parent="AppTheme.Base">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>>
    <item name="colorAccent">@color/accent</item>
    <item name="colorButtonNormal">@color/primary</item>
</style>

<style name="ToolbarTheme" parent="Widget.AppCompat.Toolbar">
    <item name="android:background">@color/primary</item>
    <item name="background">@color/primary</item>
    <item name="titleTextAppearance">@style/ToolbarTitleTheme</item>
    <item name="popupTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
    <item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>

<style name="ToolbarTitleTheme">
    <item name="android:textSize">@dimen/text_large</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:textStyle">bold</item>
</style>

Upvotes: 4

Related Questions