Problem reason: Toolbar compatibility problem
Workaround:
Setsupportactionbar (toolbar);
Toolbar steps to use:
1, write Menu.xml
In order to maintain compatibility it is necessary to write:
android:showasaction= "Ifroom"
app:showasaction= "Ifroom"
Ignore as warnings
<?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/advertise"android:checkable="true"Android:icon="@mipmap/icon_connected"android:orderincategory=" -"Android:title="AD"android:visible="true"android:showasaction="Ifroom"app:showasaction="Ifroom"/> <Item Android:id="@+id/add_friends"android:checkable="true"Android:icon="@mipmap/ic_launcher"android:orderincategory=" -"Android:title="Add Friends"android:visible="true"android:showasaction="Ifroom"app:showasaction="Ifroom"/></menu>
2. Rewriting Oncreateoptionsmenu and Onoptionsitemselected methods
After the completion of the two steps, toolbar still does not show the need for a third step
3. Resolve compatibility issues:
Called after initializing toolbar:
Setsupportactionbar (toolbar);
Android Fix toolbar title does not show problems