How to set a custom color for the popup of action items, including of the overflow menu?

浪子不回头ぞ 提交于 2019-12-06 01:03:03
Mattia Maestrini

You can customize overflow menu with the popupTheme attribute:

<android.support.v7.widget.Toolbar
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="@dimen/triple_height_toolbar"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

Original answer was missing some points:

First, the toolbar should have:

  <android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:theme="?attr/actionBarTheme"/>

For light popup, use this:

  <style name="AppTheme.Light" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarTheme">@style/AppTheme.ActionBarTheme.Light</item>
    <item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
  </style>

  <style name="AppTheme.ActionBarTheme.Light" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="colorControlActivated">#FFffffff</item>
    <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
  </style>

For dark popup, use this:

  <style name="AppTheme.Light" parent="@style/Theme.AppCompat.NoActionBar">
    <item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
    <item name="actionBarTheme">@style/AppTheme.ActionBarTheme.Dark</item>
  </style>

  <style name="AppTheme.ActionBarTheme.Dark" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="colorControlActivated">#FFffffff</item>
    <item name="android:textColorPrimary">#FFffffff</item>
  </style>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!