Trying to put a menu item on the action bar. To do this, created the following markup:

<?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=".MainActivity"> <item android:id="@+id/action_create_order" android:icon="@drawable/ic_action_new_event" android:orderInCategory="1" app:showAsAction="always" android:title="@string/action_create_order" /> <item android:id="@+id/action_settings" android:orderInCategory="100" android:title="@string/action_settings" app:showAsAction="never" /> </menu> 

In the activity I set the menu like this (inherited from the Activity class):

 @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return super.onCreateOptionsMenu(menu); } 

The application uses the theme android:Theme.Material.Light .


As a result, only the application name and the additional area with actions (three dots) in which the action element is located is displayed. Why is this happening and how to fix it?

  • Those. action_create_order no point for this action_create_order ? .. - Yuriy SPb
  • app: showAsAction = "never" because of this, most likely - Android Android android
  • Maybe instead of the app:showAsAction you need to write android:showAsAction , since it is not activated from support? - YurySPb
  • @YuriySPb, the item is in the drop-down list of actions. When I try to write android:showAsAction error Should use app:showAsAction with the appcompat library with xmlns:app="http://schemas.android.com/apk/res-auto" . - user189127
  • @AndroidAndroid, this parameter will apply to another item. - user189127

1 answer 1

According to the book really does not work. You need to write android: showAsAction = "ifRoom" and android: showAsAction = "never". Android Studio will complain that Should use app: showAsAction with the app library with xmlns: app = "http://schemas.android.com/apk/res-auto", but the application will compile and run as expected (if you remove the dependency on the libraries support, there will be no warnings).

  • How would you be a little late .... :)) - user189127