I'm not sure if this is a bug or somehow I'm not using the new Toolbar class properly.
I'm able to successfully theme the ActionBar directly using one of the available themes. This also allows me to theme the ActionMode. Everything works perfect as expected. Here is how I'm doing that.
<style name="Theme.ActionBar" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionModeBackground">@drawable/action_mode_background</item>
</style>
Now I'm looking for a little more flexibility so I'm trying to use the new Toolbar from the support library. Perfect the Toolbar implemented and working fine, however, now the action mode no longer working as expected. The custom background not working and the action mode bar is pushing the Toolbar down.
To fix the pushing down issue I used the flag windowActionModeOverlay
. To me the fact that the action mode doesn't become part of the Toolbar sucks... :/
<style name="Theme.ActionBar" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
<item name="actionModeBackground">@drawable/action_mode_background</item>
</style>
In my Activity I do the following to make my Toolbar the default ActionBar.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolBar);
setSupportActionBar(toolbar);
Right now I have tried so many things. I even tried diving into the source to figure out what is going on.
Any ideas why this is happening? How can I style the ActionMode? Or more specifically how can I change the background of the ActionMode?
Update 1
I noticed that when adding <item name="windowActionBar">false</item>
to my activity theme the action mode looses its theme versus having it as true. Obviously setting it as true it would include the window action bar.
Update 2
I was able to get the action mode themed properly using a couple mods.
The action mode background. Turns out you just set the background directly on the ActionMode theme as android:background! Also, the text you need to specify it on the theme.
<item name="actionModeStyle">@style/Widget.ActionMode</item>
<style name="Widget.ActionMode" parent="@style/Widget.AppCompat.ActionMode"> <item name="android:background">@drawable/action_mode_background</item> <item name="titleTextStyle">@style/TitleTextStyle</item> </style>
The back arrow not getting styled. I overwrote the drawable used and just added my own in white.
<item name="actionModeCloseDrawable">@drawable/ic_arrow_back_white_24dp</item>