1. Easy to use
@Override Public Boolean Oncreateoptionsmenu (Menu menu) { getmenuinflater (). Inflate (R.menu.menu_main,menu); return true ; }
<menu xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:app= "http// Schemas.android.com/apk/res-auto "> <item android:id=" @+id/share "android:icon=" @mipmap/share "Android: title= "Share" app:showasaction= "Always" ></item> <item android:id= "@+id/star" android:icon= "@ Mipmap/star "Android:title=" collection "app:showasaction= Always" ></item></menu>
2. Using a custom Actionview
Sometimes it is possible to implement the form of a text + picture, which requires us to customize a layout
<item android:id= "@+id/good" android:icon= "@mipmap/good" android:title= "likes" app:showasaction= "Always" app: actionlayout= "@layout/tool_bar_icon_good_layout" ></item>
3. Refresh Menu
Can call
Invalidateoptionsmenu ();
Supportinvalidateoptionsmenu ();
When the method is called, the system triggers
public boolean Onprepareoptionsmenu (Menu menu) {... }
Problems with Android Menu