How to add an image with text in menu options in Android?

Baskar P picture Baskar P · Aug 25, 2016 · Viewed 8.2k times · Source

I'm trying to implement a customized menu option with both, text and image, which looks like this image:

Menu Screenshot

Unfortunately I don't know how to implement this.

My menu.xml looks like:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.admin.ddcart.LIST">

    <item android:id="@+id/action_settings1"
        android:title="@string/action_settings1"
        android:orderInCategory="100" 
        app:showAsAction="never" />

    <item android:id="@+id/action_settings2"    
        android:title="@string/action_settings2"
        android:orderInCategory="100" 
        app:showAsAction="never" />

     <item android:id="@+id/action_settings3" 
         android:title="@string/action_settings3"
         android:orderInCategory="100" 
         app:showAsAction="never" />

</menu>

Answer

Deepak John picture Deepak John · Aug 25, 2016

Add android:icon=@drawable/your_image" in attribute to the item tag

 <item android:id="@+id/action_settings2"    
       android:title="@string/action_settings2"
       android:icon=@drawable/your_image"/>

and you need to use spinner refer these links http://www.androidhive.info/2013/11/android-working-with-action-bar/

https://developer.android.com/guide/topics/ui/controls/spinner.html