Cant get the Icons to show on overflow menu in android app

93 views Asked by At

No matter what I do the overflow menu in android refuses to show the menu icons, it shows the titles but not the icons, it will show only one icon on the action bar itself if I put the item in an ifRoom or always state but not in the overflow menu itself. I am using the Activity state not appcompatActivity state and can't change that because that will force me to rewrite the whole app from the beginning which is not an option. So what can I do? the code sample of the menu Includes an icon on the first item, but it is the same result if I add icons to other items.

I have tried to change items status from ifRoom to Allways to Never to With Text or even to blank title with icon only, I even tried using the Java code to connect the items with the icons, but outside one icon on the action bar itself no other icons appear

<item
    android:id="@+id/info_menu_item"
    android:icon="@android:drawable/ic_menu_help"
    android:showAsAction="never"
    android:title="@string/how_to_use"
    android:visible="true"
    tools:ignore="AppCompatResource" />

The expected result should be the appearance of the menu item in the overflow menu with title and icon, but the actual result is a title without an icon.

1

There are 1 answers

0
RumburaK On

Yes you can! The trick is to replace the overflow menu with a sub-menu like this:

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

    <item
        android:icon="@drawable/ic_baseline_more_vert_24"
        android:title=""
        app:showAsAction="always">

        <menu>
            <item
                android:id="@+id/action_download"
                android:icon="@drawable/ic_save_white_24dp"
                android:orderInCategory="101"
                android:title="@string/download_playlist"
                app:showAsAction="never" />

            <item ... />

            <item ... />

        </menu>

    </item>

</menu>

Items that are shown in a sub-menu don't have their icons hidden. So we use a submenu instead of the overflow menu!

A short and sweet tutorial available here: https://www.codingdemos.com/android-options-menu-icon/