Actionlayout on menuitem does nothing

I set actionLayout to a menu item and set the background color and image, but this is not respected. In my activity I:

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

my submit_action:

 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/action_submit" android:actionLayout="@layout/check" app:showAsAction="always" /> </menu> 

my layout check

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" style="?android:attr/actionButtonStyle" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#e8e8e8" android:clickable="true" android:contentDescription="lol" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@null" android:scaleType="centerInside" android:src="@drawable/ic_action_tick" /> </RelativeLayout> 

but even with all this setting it looks like an action bar that does not display my menu item at all (but it is there because it responds to a click, but does not appear):

enter image description here

+52
android android-actionbar android-menu
Apr 22 '14 at 6:14
source share
4 answers

Try app:actionLayout="@layout/check" instead of android:actionLayout="@layout/check" .

If you use ActionbarSherlock or AppCompat , the android: namespace will not work for MenuItem s. This is due to the fact that these libraries use custom attributes that mimic the Android API, since they did not exist in earlier versions of the framework.

+212
Apr 22 '14 at 19:54
source share

when using Appcompact, the menu item will look like

 <item android:id="@+id/cart" app:actionLayout="@layout/actionbar_cart" android:title="@string/action_cart" app:showAsAction="always" /> 

+6
Oct 24 '15 at 6:03
source share

The answer from Ben Harris is absolutely correct. However, in some cases, for example, when using attributes such as:

  app:showAsAction="ifRoom|collapseActionView" 

which is used in SearchView (in my case), the layout is not displayed and causes a lot of headache. CollapseActionView does not seem to be supported with action view in appcombat. So think about it when doing your things.

+5
Mar 19 '15 at 18:55
source share

use the application namespace instead of Android, and it will work fine.

 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/action_submit" app:actionLayout="@layout/check" app:showAsAction="always" /> </menu> 
0
Jul 08 '19 at 7:02
source share



All Articles