Android在Activity中与Fragment中创建自定义菜单的区别

时间:2023-06-23 21:29:14

区别就在这里,Activity中添加菜单要这样:

public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.main_menu,menu); return super.onCreateOptionsMenu(menu); }

  而在Fragment中要这样:

 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.uper, menu);
super.onCreateOptionsMenu(menu,inflater); }