Arun
Arun

Reputation: 214

Android menu item with icon

Can you please tell me how can I create an android menu item with icon. Im insert image from menu main.xml but not working

<item
    android:id="@+id/menu_settings"
    android:icon="@drawable/ic_launcher"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>
<item
    android:id="@+id/menu_cut"
    android:icon="@drawable/ic_launcher"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="cut"/>
<item
    android:id="@+id/menu_copy"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="copy"/>
<item
    android:id="@+id/menu_past"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="past"/>

Upvotes: 3

Views: 10765

Answers (5)

J.D.
J.D.

Reputation: 1411

Try this will help you to understand menu

Upvotes: 0

Martin Golpashin
Martin Golpashin

Reputation: 1062

You need to set showAsAction as ifRoom|withText

<item
    android:icon="@drawable/img"
    android:title="title"
    android:showAsAction="ifRoom|withText" />

Upvotes: 7

Pankaj Sharma
Pankaj Sharma

Reputation: 679

It's not supported in Android 3.0+ http://android-developers.blogspot.in/2012/01/say-goodbye-to-menu-button.html

Help this helps.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007584

Icons are used for toolbar buttons. You have android:showAsAction="never", forcing this item into the overflow. The overflow does not use icons.

Upvotes: 1

Dhwanik Gandhi
Dhwanik Gandhi

Reputation: 685

programmatically set the icon like this:

     menu.add(0, MENU_QUIT, 0, "Quit").setIcon(R.drawable.menu_quit_icon);

or You can set it in your xml layout like this:

    <item android:id="@+id/save_button"
          android:icon="@android:drawable/ic_menu_save"
          android:title="Save Image"/>

Upvotes: 0

Related Questions