androidxmlmenuitemoverflow-menu

(android) Why doesn't app:actionLayout="" work?


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>

Solution

  • 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.