对于 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>
查看这篇文章以获得另一种可能的解决方案。
希望对你有帮助
关于Android - Material 设计 - 如何设置上下文菜单的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34520522/