Today try to replace Actionbar with the latest toolbar on Android, and find that the menu item is never displayed after use. The XML file is as follows:
<menu xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
tools:context= "Com.example.timebeta.SettingActivity" >
<item
Android:id= "@+id/action_save"
android:icon= "@drawable/ic_done"
android:orderincategory= "100"
Android:showasaction= "Always"
android:title= "@string/action_settings"/>
</menu>
After Google discovered the problem of namespaces, after using toolbar, you need to define a new namespace in XML, showasaction can take effect. The correct XML code is as follows:
<menu xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
tools:context= "Com.example.timebeta.SettingActivity"
xmlns:app= "Http://schemas.android.com/apk/res-auto"
>
<item
Android:id= "@+id/action_save"
android:orderincategory= "100"
app: showasaction= "Always"
android:title= "@string/action_settings"
android:icon= "@drawable/ic_done"
/>
</menu>
Showasaction invalid problem resolution after using toolbar