Android actionLayout not showing with Toolbar
Asked Answered
F

3

15

I'm trying to show custom layout as an item in options menu. And this is what I have done so far

<item
    android:id="@+id/action_profile"
    android:orderInCategory="100"
    android:title="Profile"
    android:actionLayout="@layout/layout_menu_profile"
    app:showAsAction="never" />

I tried

    app:actionLayout="@layout/layout_menu_profile"

as well as per this SO link but still it shows only title - Profile

I have created new project through Android Studio 1.5 with Blank Activity. with minSDK = 15 and targetSDK = 23

Following is the code in Blank Activity.

@Override
 public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.menu_home, menu);

    MenuItem item = menu.findItem(R.id.action_profile);


    return true;
}

where am I going wrong ?

Frivolous answered 21/2, 2016 at 11:14 Comment(1)
S
66

use app:actionLayout instead of android:actionLayout.

<item
   ...
   app:actionLayout="@layout/layout_menu_profile"  
   app:showAsAction="always" />
Saar answered 12/6, 2017 at 10:44 Comment(1)
Custom menu item is visible only when i set app:showAsAction="ifRoom"Persistent
F
2

Try this code

<item
android:id="@+id/action_profile"
android:orderInCategory="100"
android:title="Profile"
android:actionLayout="@layout/layout_menu_profile"
app:showAsAction="always" />

Just set the showAsAction elements to always

Feathering answered 29/3, 2017 at 9:52 Comment(3)
i just did that its not working, but when i added app:actionLayout instead of android:actionLayout it's workingMendiola
That works, but what if I don't want to show it always?Fertile
you can use "ifRoom" instead of "always"Acetal
M
2

Use "app:" instead of "android:"

app:actionLayout="@layout/layout_menu_profile"
Manicure answered 22/6, 2022 at 16:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.