android:PopuBackground不适用于上下文菜单

android:PopuBackground不适用于上下文菜单,android,xml,android-contextmenu,Android,Xml,Android Contextmenu,为什么我的styles.xml代码成功地更改了我的actionbar溢出菜单的背景色,但未能更改我的应用程序中上下文菜单的背景色 <style name="AppBaseTheme" parent="Theme.AppCompat.Light"> <!--<item name="android:actionBarStyle">@style/DarkActionBar</item> --> </style> <!-- A

为什么我的
styles.xml
代码成功地更改了我的actionbar溢出菜单的背景色,但未能更改我的应用程序中上下文菜单的背景色

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
    <!--<item name="android:actionBarStyle">@style/DarkActionBar</item> -->

</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">

    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="android:popupMenuStyle">@style/MyPopupMenu</item>
    <item name="android:itemTextAppearance">@style/MyCustomMenuTextAppearance</item>

</style>

<!-- Popup Menu Background Color styles -->
<!-- <style name="MyPopupMenu"  parent="@android:style/Widget.Holo.ListPopupWindow"> -->
<!-- <style name="MyPopupMenu"  parent="@android:style/Widget.PopupMenu"> -->
<style name="MyPopupMenu"  parent="@style/Widget.AppCompat.PopupMenu">
    <item name="android:popupBackground">@color/dark_gray</item> 
</style>
<!-- Popup Menu Text Color styles -->
<style name="MyCustomMenuTextAppearance">
    <item name="android:textColor">@color/white</item>
</style>
为了完整起见,这里是我的上下文菜单xml,
shopping\u list\u name\u context.xml


您需要像这样覆盖actionModeBackground:

<item name="android:actionModeBackground">@drawable/context_menu</item>
@drawable/context\u菜单

可能重复的问题:

下面是上下文菜单中设置背景的代码,它的工作方式很有魅力

在styles.xml文件中,输入以下代码:

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">

  <item name="android:itemBackground">@android:color/holo_green_dark</item>

</style>

@安卓:彩色/全息绿/深色
尝试添加以下内容:

<item name="android:popupBackground">@android:color/white</item>
@android:color/white
我希望有帮助

在应用程序栏XML中:

app:popupTheme="@style/MyCustomOverflowTheme"
然后在styles.xml中:

<style name="MyCustomOverflowTheme" parent="Theme.AppCompat.Light">
    <item name="android:textColorPrimary">@color/primaryColor</item>
    <item name="android:textColorSecondary">@color/accentColor</item>
    <item name="android:background">@color/accentColor</item>
</style>
应作为工具栏或ActionBar属性,例如:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/primaryColor"
    app:theme="@style/MyCustomToolBarTheme"
    app:popupTheme="@style/MyCustomOverflowTheme"
    >
</android.support.v7.widget.Toolbar>

您是否尝试在ActionBar主题中加入“android:actionModeBackground”

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- main theme -->
    .....
    <item name="actionBarStyle">@style/AppTheme.ActionBar</item>

    <!-- if you're using Toolbar you have to put this -->
    <item name="windowActionModeOverlay">true</item>

</style>

<style name="AppTheme.ActionBar" parent="Theme.AppCompat.Light">
         .....
    <item name="android:actionModeBackground">@color/theme_ambiance_dark</item>
        .....
</style>

.....
@style/AppTheme.ActionBar
真的
.....
@颜色/主题\氛围\深色
.....

我通过使用“contextPopupMenuStyle”而不是“popupMenuStyle”来实现它。

你能发布你的AppManifest.xml吗?好的,现在已经添加了它的相关部分。检查这个stackoverflow。我不得不求助于改变前景颜色,但从那以后我有了很多新的答案,所以我现在就去看看…@Heyyou我已经尝试了所有的建议,但是没有一个有效。我想一些回答者认为这是我试图更改的溢出菜单,当我实际上试图更改长按视图(在本例中为自定义文本视图)后显示的上下文菜单时。我已将其添加到我的
元素中(并创建了可绘制的nodpi/context\u menu.xml)但我担心它不起作用。谢谢,但它只会改变溢出菜单背景颜色-而不是上下文菜单背景颜色。嘿,兄弟,你只在样式中添加了一行itemcound,我必须在我的答案中更新,并删除所有其他行,它就像一个符咒,我已经测试过了,你能告诉我你什么时候更新了你答案中的代码吗?我会再试一次。如上所示,我已经添加了android:itemBackground应用程序风格。只需放一行并检查它。它可以工作我已经在我的应用程序中测试过了。干杯,但是我在第二行得到了这个错误:
错误:错误:没有找到与给定名称匹配的资源:attr'popupBackground'。
您的Taargetsdk版本是什么?目标sdk版本是14。删除这行:@android:color/white谢谢。你能澄清一下app:popupTheme=“@style/MyCustomOverflowTheme”行应该放在哪里吗?刚刚注意到你的编辑。上下文菜单不是通过工具栏或操作栏显示的,而是通过长按自定义文本视图显示的。我已尝试添加
xmlns:app=”http://schemas.android.com/apk/res-auto“
应用程序:popupTheme=“@style/MyCustomOverflowTheme”
到xml中的自定义文本视图,但我刚刚得到
错误:在包'com.example.myapp'
中找不到属性'popupTheme'的资源标识符。您遇到了一个错误,因为TextView无法使用此属性。谢谢,是的。结果是,这对我来说不是一个解决方案。
<style name="MyCustomOverflowTheme" parent="Theme.AppCompat.Light">
    <item name="android:textColorPrimary">@color/primaryColor</item>
    <item name="android:textColorSecondary">@color/accentColor</item>
    <item name="android:background">@color/accentColor</item>
</style>
app:popupTheme="@style/MyCustomOverflowTheme"
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/primaryColor"
    app:theme="@style/MyCustomToolBarTheme"
    app:popupTheme="@style/MyCustomOverflowTheme"
    >
</android.support.v7.widget.Toolbar>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- main theme -->
    .....
    <item name="actionBarStyle">@style/AppTheme.ActionBar</item>

    <!-- if you're using Toolbar you have to put this -->
    <item name="windowActionModeOverlay">true</item>

</style>

<style name="AppTheme.ActionBar" parent="Theme.AppCompat.Light">
         .....
    <item name="android:actionModeBackground">@color/theme_ambiance_dark</item>
        .....
</style>