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?
action_create_order
no point for thisaction_create_order
? .. - Yuriy SPb ♦app:showAsAction
you need to writeandroid:showAsAction
, since it is not activated from support? - YurySPb ♦android:showAsAction
errorShould use app:showAsAction with the appcompat library with xmlns:app="http://schemas.android.com/apk/res-auto"
. - user189127