覆盖 Android 中的上下文菜单颜色 [英] Override context menu colors in Android
问题描述
让我们看看,
我知道如何更改 ListView 的样式(选择项目时的橙色):
i know how to change the style of a ListView (the orange color when an item is selected):
android:listSelector="@drawable/xxx" 和一个带有位图或 @color 的 drawable
android:listSelector="@drawable/xxx" and a drawable with a bitmap or a @color
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/image" />
<item android:drawable="@android:color/transparent" />
</selector>
问题是,为了有一个连贯的设计,我必须对上下文菜单做同样的事情,但我看不到在哪里改变它.没有 listSelector,没有什么可改变的.
The thing is, in order to have a coherent design, i have to do the same thing for a context menu but i just can't see where to change it. There is no listSelector, nothing to change.
推荐答案
如果上下文菜单是指长按的菜单,那么我已使用以下代码完成此操作.我的菜单有我的主题背景和绿色突出显示.
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.
上下文菜单布局:
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/resetConfirm" android:title="@string/actual_reset"></item>
</menu>
styles.xml,我在其中使用自定义主题(我认为这是关键)
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 中的上下文菜单颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!