I'm going to assume you're using the latest (21.x.x) appcompat-v7 library and have adpoted the new Toolbar
widget. To achieve what you want you don't modify your main app theme (except for the text selection action mode) but apply a style to the Toolbar
element in your layout (style="@style/Widget.YourApp.Toolbar"
). The style definition may look similar to this:
<style name="Widget.YourApp.Toolbar" parent="Widget.AppCompat.Toolbar">
<item name="android:background">#111</item>
<item name="android:elevation" tools:ignore="NewApi">8dp</item>
<item name="theme">@style/ThemeOverlay.YourApp.ActionBar</item>
<item name="popupTheme">@style/ThemeOverlay.YourApp</item>
</style>
For what you're trying to achieve the popupTheme
is the most important attribute. It points to another style definition which will describe the look of the toolbar's popup menu.
<style name="ThemeOverlay.YourApp" parent="ThemeOverlay.AppCompat">
<item name="android:colorBackground">#f00</item>
<item name="android:textColor">#ff0</item>
</style>
Important: Notice that you'll be using this as a theme not a style. When you apply a style the attributes are set only to the one layout element you specify it at. When you apply a theme the attributes propagate to all its children. That's why when using themes you never override the background
(which would cause overdraw and undesired looks) in favor of more specific attributes like windowBackground
or colorBackground
(which apply only to the relevant top element).
To make this example complete I'll include a toolbar theme as well:
<style name="ThemeOverlay.YourApp.ActionBar" parent="ThemeOverlay.AppCompat.ActionBar">
<!-- these color action bar title and subtitle -->
<item name="android:textColorPrimary">#00f</item>
<item name="android:textColorSecondary">#0ff</item>
<!-- this colors the icons (apply manual tinting for non-appcompat icons programmatically) -->
<item name="colorControlNormal">#0f0</item>
<!-- bug in the library - the overflow icon on Lollipop will now respect the above -->
<item name="android:colorControlNormal" tools:ignore="NewApi">?colorControlNormal</item>
<!-- these color the text of action items -->
<item name="actionMenuTextColor">?colorControlNormal</item>
</style>
Remember: When using custom text colors, use a selector and define the disabled color as well (doubly so if you're using the color on a button or in a menu).
EDIT
The above solution is said not to apply to contextual action bar or action mode popup. I found out that it's controlled by the following attribute defined on the activity theme:
<item name="actionModePopupWindowStyle">?attr/popupWindowStyle</item>
The default value points to @style/Widget.PopupMenu
which is defined as follows:
<style name="Widget.PopupWindow">
<item name="popupBackground">@drawable/editbox_dropdown_background_dark</item>
<item name="popupAnimationStyle">@style/Animation.PopupWindow</item>
</style>
Create a custom style based on Widget.PopupWindow
and point to it from actionModePopupWindowStyle
.
actionModePopupWindowStyle
inplatform_frameworks_base/core/res/res/values/themes.xml
andWidget.PopupWindow
inplatform_frameworks_base/core/res/res/values/styles.xml
but overriding it in my styles doesn't seem to have an effect. – Burglarious