工具栏选项菜单背景颜色 [英] Toolbar options menu background color

查看:279
本文介绍了工具栏选项菜单背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的工具栏机器人。 我只是想改变溢出菜单的背景颜色。但它并没有改变。

XML样式

 <样式名称=MyDarkToolbarStyle父=Widget.AppCompat.Toolbar>
    <项目名称=popupTheme> @风格/ PopupMenuStyle< /项目>
    <项目名称=主题> @风格/ ThemeOverlay.AppCompat.Dark.ActionBar< /项目>
< /风格>

<样式名称=PopupMenuStyle父=机器人:Widget.Holo.Light.PopupMenu>
    <项目名称=机器人:popupBackground> @android:彩色/白< /项目>
< /风格>
 

工具栏XML

 < android.support.v7.widget.Toolbar
    机器人:ID =@ + ID / tool_bar
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:背景=@色/ ColorPrimary
    机器人:海拔=2DP
    机器人:主题=@风格/ MyDarkToolbarStyle/>
 

解决方案

要更改的工具栏选项菜单的颜色,添加到您的工具栏元素

 应用程序:popupTheme =@风格/ MyDarkToolbarStyle
 

然后在你的 styles.xml 定义弹出菜单样式

 <样式名称=MyDarkToolbarStyle父=ThemeOverlay.AppCompat.Light>
    <项目名称=机器人:colorBackground> @色/ mtrl_white_100< /项目>
    <项目名称=机器人:文字颜色> @色/ mtrl_light_blue_900< /项目>
< /风格>
 

请注意,您需要使用 colorBackground 不可以 背景。后者将被应用到一切(菜单本身和每个菜单项),前者仅适用于弹出式菜单。

I am using the toolbar for android. I just want to change the background color of the overflow menu. But it is not changing.

Style xml

<style name="MyDarkToolbarStyle" parent="Widget.AppCompat.Toolbar">
    <item name="popupTheme">@style/PopupMenuStyle</item>
    <item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>

<style name="PopupMenuStyle" parent="android:Widget.Holo.Light.PopupMenu">
    <item name="android:popupBackground">@android:color/white</item>
</style>

Toolbar XML

    <android.support.v7.widget.Toolbar
    android:id="@+id/tool_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/ColorPrimary"
    android:elevation="2dp"
    android:theme="@style/MyDarkToolbarStyle" />

解决方案

To change the toolbar options menu color, add this to your toolbar element

app:popupTheme="@style/MyDarkToolbarStyle"

Then in your styles.xml define the popup menu style

<style name="MyDarkToolbarStyle" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:colorBackground">@color/mtrl_white_100</item>
    <item name="android:textColor">@color/mtrl_light_blue_900</item>
</style>

Note that you need to use colorBackground not background. The latter would be applied to everything (the menu itself and each menu item), the former applies only to the popup menu.

这篇关于工具栏选项菜单背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆