I'm using overflow menu in basic Navigation Drawer.
And I want to display icon and text at menu item.
But whatever I do doesn't work.
These are the ways I tried in menu.xml code.
First, It's an ordinary way to put 'android:icon' 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"
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>
Second, Using 'android:actionLayout=""' code
<?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"
android:actionLayout="@layout/overflow_menu_title"
app:showAsAction="never" />
<item
android:id="@+id/settings3"
android:orderInCategory="150"
android:icon="@drawable/ic_search_black_24dp"
android:actionLayout="@layout/overflow_menu_title"
android:title="setting2"
app:showAsAction="never" />
</menu>
overflow_menu_title.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>
I tried to any way but everyting failed.
I don't know why I can't put an icon in it.
please help me...
thank you.
Try to use a
PopupMenu
with youroverflow_menu.xml
.Create a function in your activity to initialize the popup:
Then call this function in your
onCreate
method.If you are using a default
Toolbar
or the defaultActionBar
from the Android theme you may want to implement your customToolbar
layout:Also, simplify your
overflow_menu
like this: