1

enter image description here

Hi

I'm using Navgation Drawer.

I want to change from text to text and icon at overflow menu items.

So i used 'android:icon' and 'android:title' in menu.xml. But Anything is not displayed.

To be exact, I could only see text.

and

I used android:actionLayout="@layout/overflow_menu_item". In overflow_menu_title, Text and Icon are defined.

But It dosen't work, too

I don't no why it dosen't work.

How to set Text and icon in overflow menu item?

I searched a lot but it didn't help.

plz help me...

Here is Code

overflow_menu.xml

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MovieList">
    <item
        android:id="@+id/menu_movie"
        android:orderInCategory="150"
        android:icon="@drawable/ic_search_black_24dp"
        android:title="setting1"
        android:actionLayout="@layout/overflow_menu_title"
        app:showAsAction="never" />
    <item
        android:id="@+id/menu_gallery"
        android:orderInCategory="150"
        android:title="setting2"
        android:icon="@drawable/ic_search_black_24dp"
        app:showAsAction="never" />

    <item
        android:id="@+id/settings3"
        android:orderInCategory="150"
        android:icon="@drawable/ic_search_black_24dp"
        android:title="setting2"

        app:showAsAction="never" />
</menu>

overflow_menu_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:gravity="center_vertical"
    android:padding="2dp"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryDark">

    <ImageView
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:src="@drawable/ic_15"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="MOVIE"
        android:textSize="24dp"/>
</LinearLayout>
ybybyb
  • 1,385
  • 1
  • 12
  • 33
  • 1
    Does this answer your question? [How To show icons in Overflow menu in ActionBar](https://stackoverflow.com/questions/18374183/how-to-show-icons-in-overflow-menu-in-actionbar) You don't see the icons because they aren't supposed to be shown. The solution is to use reflection to force show them. – Nicolas Dec 15 '20 at 19:32
  • Thank you, but it doesn't work too TT – ybybyb Dec 16 '20 at 15:17

1 Answers1

1

You can't create a custom layout for menu item using android:actionLayout for items that are not on the action bar.

In other meaning, you can't set android:actionLayout for non-action items that are in the overflow menu items.

Zain
  • 37,492
  • 7
  • 60
  • 84
  • You mean I can't use android:actionLayout for overflow menu items? So What should I do to use an android:actionLayout? Is there any good way? I want to display icon and text on overflow menu 'items' – ybybyb Dec 20 '20 at 19:28
  • You can only use it to add actions on the Actionbar itself like in [this](https://stackoverflow.com/questions/65174901/adding-text-below-above-a-switch-button-in-android-menu-icon/65175618#65175618#answer-65175618) answer .. which is in front of the user on the ActionBar (not the overflow 3 dots icon) – Zain Dec 20 '20 at 19:35
  • I understood roughly. Are you saying that android:actionLayout can only use in actionbar and menu item are impossible? Then, what are some ways to set icon and text in menu items? – ybybyb Dec 20 '20 at 19:47
  • Yeah that what I mean `android:actionLayout` can only be used in `actionbar` to have a custom layout for `ActionBar` item, but not in the `three-dots` overflow menu.. Do you want to add icons to the Overflow menu items? – Zain Dec 20 '20 at 19:54
  • @ybybyb Can you check [this](https://stackoverflow.com/questions/35490999/can-i-use-a-actionlayout-on-the-overflow-menu-of-android-support-v7-widget-toolb/35732788#answer-35732788) answer is what you are asking about – Zain Dec 20 '20 at 20:07