为什么图片/图标不显示在菜单呢? [英] Why the pictures/icon don't show up in the menu?

查看:134
本文介绍了为什么图片/图标不显示在菜单呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跟着本教程创建菜单

但我的菜单看起来是不同的:

我如何可以创建图像的菜单?

这是我的code:

 <菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目机器人:ID =@ + ID / preferences
        机器人:图标=@可绘制/ preferences
        机器人:标题=preferences/>
    <项目机器人:ID =@ + ID /帮助
        机器人:标题=帮助
        机器人:图标=@可绘制/ ic_action_search/>
< /菜单>

@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
        /*menu.add(Menu.NONE,preF_ID,Menu.NONE,preferences)
                .setIcon(R.drawable preferences。).setAlphabeticShortcut('E');

        返程(super.onCreateOptionsMenu(菜单)); * /
        MenuInflater充气= getMenuInflater();
        inflater.inflate(R.menu.activity_ygo_main,菜单);
        返回true;
    }
 

解决方案

首先我要说:的暂别菜单按钮

您code都没有问题,并且应该显示的图标,如果可绘有没有在正确的文件夹,做工精细在Android 2.2。

菜单功能说:

  1.上下文菜单:不支持项目的快捷方式和项目图标。
   2.选择菜单:图标菜单不支持项目复选标记,并只显示该项目的简明标题。扩大菜单(仅当六个或更多的菜单项是可见的,通过在图标菜单中的更多项达到)不显示的项目图标,以及项目选中标记都望而却步。
   3.子菜单:不支持的项目图标,或嵌套子菜单。
 

没有问题,你的code,问题可能与您正在使用的API级别,但还是要建议不要使用菜单了。


机器人不再需要专用的菜单按钮,有些设备没有一个,你应该使用它迁移出来。

I followed this tutorial to create a menu

but my menu looks differently:

How can I create a menu with images?

This is my code:

<menu xmlns:android="http://schemas.android.com/apk/res/android">    
    <item android:id="@+id/preferences"
        android:icon="@drawable/preferences"    
        android:title="Preferences" />
    <item android:id="@+id/help"
        android:title="Help"
        android:icon="@drawable/ic_action_search" />    
</menu>

@Override
public boolean onCreateOptionsMenu(Menu menu) {
        /*menu.add(Menu.NONE, PREF_ID, Menu.NONE, "Preferences")
                .setIcon(R.drawable.preferences).setAlphabeticShortcut('e');

        return (super.onCreateOptionsMenu(menu));*/
        MenuInflater inflater = getMenuInflater();      
        inflater.inflate(R.menu.activity_ygo_main, menu);
        return true;        
    }

解决方案

First of all I want to say : Say Goodbye to the Menu Button

Your code have no problem, and it should be showing the icons if the drawables are there in correct folder,Working fine on Android 2.2.

The Menu features says :

   1.  Context menus: Do not support item shortcuts and item icons.
   2. Options menus: The icon menus do not support item check marks and only show the item's condensed title. The expanded menus (only available if six or more menu items are visible, reached via the 'More' item in the icon menu) do not show item icons, and item check marks are discouraged.
   3. Sub menus: Do not support item icons, or nested sub menus. 

No problem with your code, Problem may be with the API level you are using, but still want to suggest that don't use Menu anymore.


Android no longer requires a dedicated Menu button, some devices don’t have one, and you should migrate away from using it.

这篇关于为什么图片/图标不显示在菜单呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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