简体   繁体   English

将android工具栏弹出菜单主题从黑暗变为光

[英]change android toolbar popup menu theme from dark to light

I am using the appcompat v22 toolbar widget 我正在使用appcompat v22工具栏小部件

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>

I want a light themed popup menu ( white background with black text ) Problem is the popup menu is always turning out be dark themed (looks like it is picking the styles from ThemeOverlay.AppCompat.Dark.ActionBar and setting android:popupTheme="@style/ThemeOverlay.AppCompat. Light" is not making any difference. 我想要一个浅色主题弹出菜单(带有黑色文本的白色背景)问题是弹出菜单总是变成黑暗主题(看起来它是从ThemeOverlay.AppCompat.Dark.ActionBar中选择样式并设置android:popupTheme =“@ style / ThemeOverlay.AppCompat.Light“没有任何区别。

The problem occurred when I moved from app:theme to android:theme ( that's what is recommended if we need to use appcompat v22 version 当我从app:theme移动到android:theme时出现问题(如果我们需要使用appcompat v22版本,那就是推荐的

I tried overriding the style and setting many values within the style 我尝试重写样式并在样式中设置许多值

<style name="ToolBarPopUpTheme" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:colorBackground">#ffffff</item>
    <item name="android:textColor">#ffffff</item>
    <item name="android:textColorPrimary">#ffffff</item>
    <item name="android:colorForeground">#ffffff</item>
    <item name="colorControlNormal">#ffffff</item>
    <item name="android:windowBackground">#ffffff</item>
</style>

But in vain, any idea how to get a light themed Popup menu in the ActionBar ? 但是没有任何想法如何在ActionBar中获得一个轻量级的主题Popup菜单?

Thanks, 谢谢,

You want to go back to app:popupTheme. 你想回到app:popupTheme。

If you look at the source code for Toolbar.java you'll see the following on line 263. 如果您查看Toolbar.java的源代码,您将在第263行看到以下内容。

setPopupTheme(a.getResourceId(R.styleable.Toolbar_popupTheme, 0));

R in this case is android.support.v7.appcompat.R (check out line 32), so the Toolbar is using the app: namespace for its attributes and not the android: namespace. 在这种情况下,R是android.support.v7.appcompat.R (检查第32行),因此Toolbar使用app: namespace作为其属性,而不是android:名称空间。

Out of curiosity, where did you read that you should be using the android:theme attribute? 出于好奇,你在哪里读到你应该使用android:theme属性?

As far as i see you are using the wrong parent style. 据我所知,你使用的是错误的父母风格。

Give this a try: 尝试一下:

<style name="ToolBarPopUpTheme" parent="@style/ThemeOverlay.AppCompat.Light" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM