NarasimhaKolla NarasimhaKolla - 4 months ago 52
Android Question

How to add images to overflow menu in Android studio?

I am developing the overflow menu for latest android version as i am doing this,the text items are being added to the overflow menu but item images are not adding. so please help me to know how to add images to the overflow menu.

I have attached screenshot and Code.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/new_game"
android:icon="@drawable/ic_new_game"
android:title="@string/new_game"
android:showAsAction="ifRoom"/>


enter image description here

Answer

In your menu xml, use the following syntax to nest menu, you will start getting the menu with icons

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/empty"
        android:icon="@drawable/ic_action_overflow"
        android:orderInCategory="101"
        android:showAsAction="always">
        <menu>
            <item
                android:id="@+id/new_game"
                android:icon="@drawable/ic_new_game"
                android:showAsAction="always|withText"
                android:title="@string/new_game" />
        </menu>
    </item>

</menu>