Nayanesh Gupte
Nayanesh Gupte

Reputation: 2775

Android actionLayout not showing with Toolbar

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 ?

Upvotes: 15

Views: 8505

Answers (3)

Oleg Dontsov
Oleg Dontsov

Reputation: 41

Use "app:" instead of "android:"

app:actionLayout="@layout/layout_menu_profile"

Upvotes: 2

Mohd Nashirudden
Mohd Nashirudden

Reputation: 769

use app:actionLayout instead of android:actionLayout.

<item
   ...
   app:actionLayout="@layout/layout_menu_profile"  
   app:showAsAction="always" />

Upvotes: 66

D G
D G

Reputation: 186

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

Upvotes: 2

Related Questions