@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Log.d("Does", "get called");
inflater.inflate(R.menu.menuitem, menu);
super.onCreateOptionsMenu(menu, inflater);
}
下面是我的 onCreateView 方法,我在这里调用
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
setHasOptionsMenu(true);
return inflater.inflate(R.layout.layout1, container, false);
}
我没有在我的操作栏中调用日志语句或菜单。
更新:我尝试从片段的 onCreate 方法调用它,但未显示菜单。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
菜单.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/section" android:title="@string/section"
android:icon="@drawable/ic_section"
android:showAsAction="always" />
<item android:id="@+id/refresh" android:title="@string/refresh"
android:icon="@drawable/ic_refresh"
android:showAsAction="always" />
<item android:id="@+id/edit_patient" android:title="@string/edit_patient"
android:icon="@drawable/ic_editpatient"
android:showAsAction="always" />
<item android:id="@+id/about" android:title="@string/about"
android:showAsAction="never" />
<item android:id="@+id/help" android:title="@string/help"
android:showAsAction="never" />
<item android:id="@+id/signout" android:title="@string/signout"
android:showAsAction="never" />
</menu>