菜单项的背景不会改变 [英] Background of MenuItem won't change

查看:108
本文介绍了菜单项的背景不会改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我张贴了关于我的code编译一个类似的问题,但我设法得到的一切运行。然而,我的code没有默认的白色背景更改为较深的颜色。这是我的code:

 < XML版本=1.0编码=UTF-8&GT?;
  <资源>
     <样式名称=主题>
        <项目名称=@安卓panelFullBackground> @android:彩色/ background_dark< /项目>
        <项目名称=@安卓panelColorBackground> @android:彩色/ background_dark< /项目>
        <项目名称=@安卓panelBackground> @android:彩色/ background_dark< /项目>
     < /风格>
  < /资源>
 

我申请的主题在这里:

 <菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
   风格=@风格/主题>
      <项目机器人:ID =@ + ID /添加/> ......
< /菜单>
 

修改:下面是从logcat的输出

 五月1日至10日:47:08.434:E / AndroidRuntime(30489):致命异常:主要
五月1号至10日:47:08.434:E / AndroidRuntime(30489):android.content.res.Resources $ NotFoundException:资源编号为0x0
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在android.content.res.Resources.getValue(Resources.java:901)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在android.content.res.Resources.getDrawable(Resources.java:589)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在com.android.internal.policy.impl.PhoneWindow.openPanel(PhoneWindow.java:500)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在com.android.internal.policy.impl.PhoneWindow.onKeyUpPanel(PhoneWindow.java:703)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在com.android.internal.policy.impl.PhoneWindow.onKeyUp(PhoneWindow.java:1475)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在com.android.internal.policy.impl.PhoneWindow $ DecorView.dispatchKeyEvent(PhoneWindow.java:1845)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2758)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2730)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在android.view.ViewRoot.handleMessage(ViewRoot.java:1999)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在android.os.Handler.dispatchMessage(Handler.java:99)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在android.os.Looper.loop(Looper.java:150)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在android.app.ActivityThread.main(ActivityThread.java:4385)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在java.lang.reflect.Method.invokeNative(本机方法)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在java.lang.reflect.Method.invoke(Method.java:507)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:849)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
五月1号至10日:47:08.434:E / AndroidRuntime(30489):在dalvik.system.NativeStart.main(本机方法)
 

解决方案

看来,机器人:panelBackground 应该是一个绘制,并不出彩。

一个很好的开始可能会被定位Android的默认九补丁SDK的平台资源(<$ C C $> menu_hardkey_panel_holo_dark.9.png ),将它们复制到自己绘制的文件夹和编辑它们。最后,阿迪尔指出,添加项目到样式声明如下:

 &LT;样式名称=AppTheme父=Theme.Sherlock&GT;
    &LT;项目名称=机器人:panelBackground&GT; @可绘制/ menu_hardkey_panel&LT; /项目&GT;
&LT; /风格&GT;
 

(注意,这里我使用ActionBarSherlock,因此父主题。)

I posted a similar question regarding my code compiling but I managed to get everything running. However, my code doesn't change the default white background to a darker color. Here is my code:

<?xml version="1.0" encoding="utf-8"?>
  <resources>
     <style name="Theme">
        <item name="@android:panelFullBackground">@android:color/background_dark</item>
        <item name="@android:panelColorBackground">@android:color/background_dark </item>
        <item name="@android:panelBackground">@android:color/background_dark</item>
     </style>
  </resources>

I'm applying the theme here:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
   style="@style/Theme">
      <item android:id="@+id/add"/>......
</menu>

Edit: Here is the output from the logcat

01-10 05:47:08.434: E/AndroidRuntime(30489): FATAL EXCEPTION: main
01-10 05:47:08.434: E/AndroidRuntime(30489): android.content.res.Resources$NotFoundException: Resource ID #0x0
01-10 05:47:08.434: E/AndroidRuntime(30489):    at android.content.res.Resources.getValue(Resources.java:901)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at android.content.res.Resources.getDrawable(Resources.java:589)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at com.android.internal.policy.impl.PhoneWindow.openPanel(PhoneWindow.java:500)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at com.android.internal.policy.impl.PhoneWindow.onKeyUpPanel(PhoneWindow.java:703)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at com.android.internal.policy.impl.PhoneWindow.onKeyUp(PhoneWindow.java:1475)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1845)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2758)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2730)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1999)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at android.os.Looper.loop(Looper.java:150)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at android.app.ActivityThread.main(ActivityThread.java:4385)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at java.lang.reflect.Method.invokeNative(Native Method)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at java.lang.reflect.Method.invoke(Method.java:507)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
01-10 05:47:08.434: E/AndroidRuntime(30489):    at dalvik.system.NativeStart.main(Native Method)

解决方案

It appears that android:panelBackground should be a drawable, not a color.

A good place to start would probably be locating Android's default nine-patch in the SDK's platform resources (menu_hardkey_panel_holo_dark.9.png), copying them to your own drawable folders and editing them. Finally, as Adil pointed out, add the items to the style declaration as:

<style name="AppTheme" parent="Theme.Sherlock">
    <item name="android:panelBackground">@drawable/menu_hardkey_panel</item>
</style>

(Note that here I'm using ActionBarSherlock, hence the parent theme.)

这篇关于菜单项的背景不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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