覆盖上下文菜单颜色的Andr​​oid [英] Override context menu colors in Android

查看:113
本文介绍了覆盖上下文菜单颜色的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们来看看,

我知道如何改变ListView的风格(当一个项目被选中橙色):

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

安卓listSelector =@可绘制/ XXX,并以位图或@Color被拉伸

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.

推荐答案

如果通过上下文菜单中你的意思是从长远preSS菜单,然后我跟以下code做到了这一点。我的菜单有我的主题的背景,和一个绿色的亮点。

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>

这篇关于覆盖上下文菜单颜色的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆