风格appcompat-V7工具栏菜单背景 [英] Style appcompat-v7 Toolbar menu background

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

问题描述

我想我的造型appcompat-V7工具栏有不同的背景颜色为我的溢出菜单。 我试图用的主题我的应用程序和样式我的工具栏,但我没能实现它。

I'm trying to styling my appcompat-v7 toolbar to have a different background color for my overflow menu. I tried to use the themes for my app and styles for my toolbar, but I was not able to achieve it.

这是我的工具栏:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"                                                                                                                              
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:layout_width="match_parent"
    app:theme="@style/AppToolbarTheme"
    android:layout_height="wrap_content">

下面是我创建的风格:

    <style name="AppToolbarTheme" parent="Theme.AppCompat.NoActionBar">
       <item name="android:textColorPrimary">@color/white</item>
       <item name="android:textColorSecondary">@color/cian</item>
    </style>

我的主题是扩大Theme.AppCompat.Light。

My main theme is extending Theme.AppCompat.Light.

有谁知道我该怎么办呢?如果无法使用的样式是有实现的任何其他方式?

Does anybody knows how can I do that? If is not possible using the styles is there any other way to achieve it?

推荐答案

添加到您的工具栏元素

app:popupTheme="@style/ThemeOverlay.YourApp"

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

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

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

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

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

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