I tried different combinations in xml file:
<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_alarm"
android:icon="@drawable/ic_action_accept"
android:orderInCategory="100"
android:title="@string/menu_create_alarm"
app:showAsAction="ifRoom|withText" />
</menu>
or
<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_alarm"
android:icon="@drawable/ic_action_accept"
android:orderInCategory="100"
android:title="@string/menu_create_alarm"
app:showAsAction="always|withText" />
</menu>
or
<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_alarm"
android:icon="@drawable/ic_action_accept"
android:orderInCategory="100"
android:title="@string/menu_create_alarm"
app:showAsAction="withText" />
</menu>
or
<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_alarm"
android:icon="@drawable/ic_action_accept"
android:orderInCategory="100"
android:title="@string/menu_create_alarm"
android:showAsAction="always|withText" />
</menu>
I tried to set it programmaticly
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
MenuItem item = menu.add(R.string.menu_create_alarm);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT|MenuItem.SHOW_AS_ACTION_IF_ROOM);
item.setIcon(R.drawable.ic_action_accept);
item.setOnMenuItemClickListener(
new OnMenuItemClickListener(){
@Override
public boolean onMenuItemClick(MenuItem item){
saveAlarm();
return true;
}
}
);
// inflater.inflate(R.menu.menu_create_alarm, menu);
super.onCreateOptionsMenu(menu, inflater);
}
or
<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_alarm"
android:icon="@drawable/ic_action_accept"
android:orderInCategory="100"
android:title="@string/menu_create_alarm"
android:showAsAction="always|withText"
app:showAsAction="always|withText" />
</menu>
However, Only Icon appears. And there is planty of room, cause I did not set toolbar title. Removing menues and replasing them with button inside toolbar is not sutable.
How to display text?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…