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

标签 android android-layout android-5.0-lollipop

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

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

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

最佳答案

只需按照以下步骤操作:

If by context menu you mean the menu from the long press, then I have done this with the following code. My menu has my theme's background, and a green highlight.

context menu layout:

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

styles.xml, where I'm using a custom theme (which I think is the key)

 <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>

From: Override context menu colors in Android

查看这篇文章以获得另一种可能的解决方案。

希望对你有帮助

关于Android - Material 设计 - 如何设置上下文菜单的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34520522/

相关文章:

android - finishActivity() 的可能用例是什么

android - 无法更改 ActionBar 大小

android - 更新到 Android Lollipop 后的 ActionBar 样式

android - Android 5.0 (API 21) 上的 Drawable setHotspot 的用途是什么?

android - 如何自定义选项卡操作栏

android - Android 5.0 上的 OpenCV for Android 问题( Lollipop )

android - Room 中的 Sum 和 Count - 别名没有这样的列

javascript - 平台工具\adb.exe : Comman d failed with exit code 3221226356

android - Fragment 中的 ListView 未显示

android - 使用多个 sdk 版本构建 cordova