Java 在Android中覆盖上下文菜单颜色
让我想想 我知道如何更改ListView的样式(选择项目时为橙色): android:listSelector=“@drawable/xxx”和带有位图或@color的drawableJava 在Android中覆盖上下文菜单颜色,java,android,user-interface,Java,Android,User Interface,让我想想 我知道如何更改ListView的样式(选择项目时为橙色): android:listSelector=“@drawable/xxx”和带有位图或@color的drawable <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:drawable="@drawable/image" />
<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>
问题是,为了有一个连贯的设计,我必须对上下文菜单做同样的事情,但我不知道在哪里可以改变它。没有列表选择器,无需更改。如果上下文菜单指的是长按的菜单,则我已使用以下代码完成此操作。我的菜单有我的主题背景和绿色高亮 关联菜单布局:
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/resetConfirm" android:title="@string/actual_reset"></item>
</menu>
styles.xml,其中我使用了一个自定义主题(我认为这是关键)
@可绘制/背景
@样式/进度条
@样式/绿色按钮
@样式/绿色按钮
@样式/列表视图
@可绘图/菜单选择器
@样式/微调器
@可绘制/背景
@可绘制/列表\选择器\背景\绿色
这是唯一适合我的方法:
您可以在应用程序主题中覆盖android属性actionModeBackground(我在android/Sdk/platforms/android-22/data/res/values/themes_holo.xml和中找到了该属性):
<style name="AppTheme" parent="android:Theme.Holo">
<item name="android:windowBackground">@color/background</item>
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionModeBackground">@drawable/context_menu</item>
...
</style>
@颜色/背景
@样式/MyActionBar
@可绘制/上下文菜单
...
换上你自己的可拉深颜色,在这种情况下
context_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/context_menu_bottom" />
<item android:drawable="@drawable/context_menu_top"/>
</layer-list>
它是由
上下文菜单\u bottom.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/accent"/>
<padding android:bottom="4dp"/>
</shape>
及
上下文菜单\u top.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/primary"/>
</shape>
希望有帮助 以下是您的操作方法。转到resources>style.xml并覆盖主题的ItemBackground属性值,如下所示:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:itemBackground">"YOUR_COLOUR_HERE"</item>
</style>
“你的颜色在这里”
如果这不起作用,请在AndroidManifet.xml中检查您是否在应用程序级别使用相同的主题:
<application
...
android:theme="@style/AppTheme">
...
</application>
...
AFAIK,您不能更改上下文菜单的选择器,因为这应该是平台的标准选择。这就是我的想法,谢谢您的回答!这就是我在ApplicationManifest.xml中应用于应用程序级别的主题
<application
...
android:theme="@style/AppTheme">
...
</application>