Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

java - Override context menu colors in Android

Let's see,

i know how to change the style of a ListView (the orange color when an item is selected):

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> 

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...