Following the docs about Android's menus, I was able to set a custom layout for one of my action bar's items (see item alwaysThere
). For another item however, it won't show the custom version but always the standard text (see 'subMenuItem'). The difference between these two items is that the 2nd one is inside of a nested submenu.
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app ="http://schemas.android.com/apk/res-auto">
<item
android:id ="@+id/alwaysThere"
android:title ="Always there"
app:showAsAction="always"
app:actionLayout="@layout/customlayout" />
<item
android:title="Root"
android:icon="@drawable/ic_people_white_24dp"
app:showAsAction="always">
<menu>
<item
android:id ="@+id/subMenuItem"
android:title ="Submenu item"
app:actionLayout="@layout/customlayout" />
[...]
Here's the result:
versus
I have alternatively tried to inflate the layout manually and use setActionView()
when creating the options menu. Same result: working for the root item but not for items in the submenu, even if explicitly calling expandActionView()
.
What do I have to do to make the submenu entries also use the custom layout?