Mokus
Mokus

Reputation: 10400

Why the pictures/icon don't show up in the menu?

I followed this tutorial to create a menu

but my menu looks differently:

menu

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;        
    }

Upvotes: 2

Views: 2752

Answers (2)

Sham
Sham

Reputation: 72

If you use some following attribute in manifest file then it's will be show your icon....

<activity android:name=".ui.CategoryActivity"
        android:label="@string/app_name"
        **android:theme="@android:style/Theme.NoTitleBar"**></activity>

It's work fine for me...:)

**must be enter.

Upvotes: 0

MKJParekh
MKJParekh

Reputation: 34301

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.

Upvotes: 4

Related Questions