更新时间:2023-11-29 23:33:58
调用超级方法:
Java:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// TODO Add your menu entries here
super.onCreateOptionsMenu(menu, inflater);
}
科特琳:
override fun void onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
// TODO Add your menu entries here
super.onCreateOptionsMenu(menu, inflater)
}
在代码中添加日志语句,以查看是否未调用该方法或菜单是否未
Put log statements in the code to see if the method is not being called or if the menu is not being amended by your code.
还请确保您在中调用
通知片段应该参与选项菜单处理。 setHasOptionsMenu(boolean)
onCreate(Bundle)
Also ensure you are calling setHasOptionsMenu(boolean)
in onCreate(Bundle)
to notify the fragment that it should participate in options menu handling.