我正在尝试使溢出菜单中的背景颜色不同于toolbar
的背景颜色。
目前是这样的:
在有人将此标记为重复之前:我已经尝试了很多事情,诸如此类的建议
How to change the background color of the options menu?
How to change background color of overflow menu (popup Menu) for action bar
How to change the background color of the overflow menu in android
但是没有任何东西对我有用。溢出菜单仍然是蓝色的。现在,我的代码如下:
我活动中的工具栏:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/CustomToolbarStyle"
android:popupTheme="@style/AppTheme.PopupOverlay" />
我的styles.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
<!-- Customize your theme here. -->
<style name="CustomToolbarStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:background">@color/colorPrimary</item>
</style>
<!-- Menu item theme here. -->
<style name="CustomPopupStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:popupMenuStyle">@color/colorAccent</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.PopupOverlay" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:colorBackground">@color/colorAccent</item>
</style>
<style name="ThemeOverlay.MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:itemBackground">@color/colorAccent</item>
<item name="android:textColor">@color/colorPrimaryDark</item>
</style>
我的colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="color_one">#FF9DEFDA</drawable>
<drawable name="color_two">#FF9DEFDA</drawable>
<drawable name="color_three">#ffcbcbcb</drawable>
<drawable name="color_four">#ff0000</drawable>
<drawable name="color_five">#ff0000</drawable>
<drawable name="color_six">#ffffffff</drawable>
<drawable name="color_seven">#FBAE9E</drawable>
<color name="colorPrimary">#0A7FDA</color>
<color name="colorPrimaryDark">#000000</color>
<color name="colorAccent">#ece6e8</color>
<color name="list_divider">#d9d9d9</color>
<color name="list_row_start_color">#ffffff</color>
<color name="list_row_end_color">#ffffff</color>
<color name="list_row_hover_start_color">#1871EF</color>
<color name="list_row_hover_end_color">#1871EF</color>
<color name="color_seven">#FBAE9E</color>
</resources>
有什么想法可以解决此问题吗? Tx。
答案 0 :(得分:1)
将此style
添加到您的Style.xml
中,然后在您的ToolBar
中设置
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" >
<item name="android:textColorSecondary">@color/colorPrimary</item>
<item name="android:textColorPrimary">@android:color/white</item>
</style>
在Activity
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" >