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

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

问题描述

我按照

您的代码没有问题,如果可绘制对象位于正确的文件夹中,它应该会显示图标,在 Android 2.2 上运行良好.

菜单功能说:

 1. 上下文菜单:不支持项目快捷方式和项目图标.2. 选项菜单:图标菜单不支持项目复选标记,仅显示项目的浓缩标题.扩展菜单(仅当六个或更多菜单项可见时可用,通过图标菜单中的更多"项到达)不显示项图标,并且不鼓励项复选标记.3.子菜单:不支持项目图标、嵌套子菜单.

你的代码没问题,问题可能出在你使用的 API 级别上,但还是想建议不要再使用 Menu.

<小时>

Android 不再需要专用的菜单按钮,有些设备没有,您应该不再使用它.

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天全站免登陆