繁体   English   中英

Android - 材质设计 - 如何设置上下文菜单的背景颜色

[英]Android - material design - how to set the background color for a context menu

对于列表视图,我有一个上下文菜单(关于项目)。 如何设置(通过样式)上下文菜单的背景颜色?

从示例中我使用了以下基本主题:

<style name="Base.Theme.Xyz" parent="Theme.AppCompat.NoActionBar">

只需按以下步骤操作:

如果通过上下文菜单表示长按菜单,那么我使用以下代码完成了此操作。 我的菜单有我的主题背景和绿色突出显示。

上下文菜单布局:

 <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/resetConfirm" android:title="@string/actual_reset"></item> </menu> 

styles.xml,我在哪里使用自定义主题(我认为是关键)

  <style name="GradientLight" parent="@android:style/Theme.Light"> <item name="android:windowBackground">@drawable/background</item> <item name="android:progressBarStyle">@style/progressBar</item> <item name="android:buttonStyle">@style/greenButton</item> <item name="android:buttonStyleSmall">@style/greenButton</item> <item name="android:listViewStyle">@style/listView</item> <item name="android:itemBackground">@drawable/menu_selector</item> <item name="android:spinnerStyle">@style/spinner</item> </style> <style name="listView" parent="@android:style/Widget.ListView.White"> <item name="android:background">@drawable/background</item> <item name="android:listSelector">@drawable/list_selector_background_green</item> </style> 

发件人: 覆盖Android中的上下文菜单颜色

查看此帖子以获取更多可能的解决方案。

希望它有所帮助

虽然我很感谢前面的回答,但我找到了完美而简单的解决方案。

在我的项目中,我使用了这个父母:

<style name="Base.Theme.Deholtmans" parent="Theme.AppCompat.NoActionBar">

我得到了非常黑暗的上下文菜单等。在AppCompat之前我使用了Light版本的主题。

解决方案是使用正确的预定义父级:

<style name="Base.Theme.Deholtmans" parent="Theme.AppCompat.Light.NoActionBar">

所以,轻型版。 轻而易举!

暂无
暂无

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

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