Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Icon with Action Bar's Option Menu Item

I want to display Action Bar's Option Menu items with Image Icon like one we use in Navigation Drawer Bar.

Right now, My app option menu is showing as below :
How do I display Image icon with Item 1, Item 2 etc.

enter image description here

like image 467
Jeeten Parmar Avatar asked Feb 09 '23 03:02

Jeeten Parmar


2 Answers

Below code solved my issue. from this link : How To show icons in Overflow menu in ActionBar

<item
    android:id="@+id/empty"
    android:icon="@drawable/ic_action_overflow"
    android:orderInCategory="101"
    android:showAsAction="always">
    <menu>
        <item
            android:id="@+id/action_show_ir_list"
            android:icon="@drawable/ic_menu_friendslist"
            android:showAsAction="always|withText"
            android:title="List"/>
    </menu>
</item>
like image 161
Jeeten Parmar Avatar answered Feb 10 '23 23:02

Jeeten Parmar


Here is the solution You are Looking for Copy this menu.xml And change icons and name as per your need in mipmap

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/main_menu"
        android:actionViewClass="android.widget.ImageButton"
        android:icon="@mipmap/menu"
        android:orderInCategory="200"
        android:title="@string/action_settings"
        app:showAsAction="always">
        <menu>
            <item
                android:id="@+id/home"
                android:icon="@mipmap/home_menu"
                android:title="Home" />
            <item
                android:id="@+id/edit_profile"
                android:icon="@mipmap/my_account"
                android:title="Profile" />
            <item
                android:id="@+id/my_account"
                android:icon="@mipmap/my_account"
                android:title="My Account" />
            <item
                android:id="@+id/messages"
                android:icon="@mipmap/message1"
                android:title="Messages" />
            <item
                android:id="@+id/notification"
                android:icon="@mipmap/notification"
                android:title="Notifications" />
            <item
                android:id="@+id/settings"
                android:icon="@mipmap/settings"
                android:title="Settings" />
            <item
                android:id="@+id/logout"
                android:icon="@mipmap/logout"
                android:title="Logout" />
        </menu>

    </item>
</menu>

Then create menu_main.xml like this

<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=".MainActivity">
    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never" />
</menu>
like image 24
Quick learner Avatar answered Feb 10 '23 23:02

Quick learner