38

I used this tutorial to facelift my Holo app for Lollipop: http://android-developers.blogspot.ru/2014/10/appcompat-v21-material-design-for-pre.html

What I have:

  1. Theme

    <style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
      <item name="windowActionModeOverlay">true</item>
      <item name="colorPrimary">@color/theme_primary</item>
      <item name="colorPrimaryDark">@color/theme_primary_dark</item>
      <item name="colorAccent">@color/theme_accent</item>
    </style>
    
  2. Toolbar layout

    <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:layout_height="wrap_content"
      android:layout_width="match_parent"
      android:minHeight="?attr/actionBarSize"
      android:background="?attr/colorPrimary"
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    
  3. Activity inherited from ActionBarActivity with a ListFragment fragment in the multi-choice mode

    getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

Result: The toolbar is OK. It uses the sepcified theme colors, but the ActionBar used by the ListFragment in the ActionMode (activated by tap-and-hold a list item) has the standard Dark.ActionBar colors. Also the popup menu of the action bar uses the dark theme.

I tried all the SO tricks, but still cannot solve that. I will appreciate any help.

BTW. I found that the dark colors of the ActionBar are caused by the toolbar's app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar", but have no idea how solve this, because this attribute is needed for the correct toolbar appearance.

Toolbar with correct colors Dark ActionBar

Andrey Shcherbakov
  • 923
  • 1
  • 8
  • 16

2 Answers2

75

Just add these two lines to the theme:

<item name="actionModeBackground">@color/theme_primary_dark</item>
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
Brian
  • 2,130
  • 22
  • 29
Andrey Shcherbakov
  • 923
  • 1
  • 8
  • 16
  • After a lot of time spent on this problem, this actually works. Thx! – Sandra Jan 14 '15 at 16:06
  • 29
    Wasted a lot of time trying to get this to work, only to realize that, in order to get this to work in AppCompat's Toolbar, you will have to remove the _"android:"_ portion of the item's name. Hoping that this helps any other people reading this thread :) – thisbytes Jan 15 '15 at 23:30
  • 1
    thanks! what about status bar color? it gets white when `actionmode` is showing? –  Jan 12 '16 at 21:55
3

This might also be helpful in addition to @Andrey Shcherbakov's answer if you want to have more control of each individual color.

<!-- action bar title text color, icon color (ie: back icon, icons when editing text)-->
<item name="android:textColorPrimary">#FFFF00</item>

<!-- action bar background color-->
<item name="android:colorBackground">#444400</item>

<!-- color of line under contextual action bar-->
<item name="colorControlActivated">#00CC00</item>
Community
  • 1
  • 1
waynesford
  • 1,688
  • 19
  • 17