本文介绍了onCreateOptionsMenu内片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经把 setHasOptionsMenu(真) onCreateView ,但我还是不能叫 onCreateOptionsMenu 里面的片段。

  @覆盖
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,
                         捆绑savedInstanceState){
   setHasOptionsMenu(真正的);
   返回inflater.inflate(R.layout.facesheet,集装箱,假);
}
 

下面是我的 onCreateOptionsMenu code。

  @覆盖
公共布尔onCreateOptionsMenu(com.actionbarsherlock.view.Menu菜单){
    。getSupportMenuInflater()膨胀(R.menu.layout,菜单);
    返程(super.onCreateOptionsMenu(菜单));
}
 

该错误消息我得到的:

解决方案

试试这个,

  @覆盖
公共无效onCreateOptionsMenu(功能菜单,MenuInflater充气){
    inflater.inflate(R.menu.menu_sample,菜单);
    super.onCreateOptionsMenu(菜单,充气);
}
 


而在的onCreate 添加此行,使选项出现在你的工具栏

  setHasOptionsMenu(真正的);
 

I have placed setHasOptionsMenu(true) inside onCreateView, but I still can't call onCreateOptionsMenu inside fragments.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
   setHasOptionsMenu(true);
   return inflater.inflate(R.layout.facesheet, container, false);
}

Below is my onCreateOptionsMenu code.

@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
    getSupportMenuInflater().inflate(R.menu.layout, menu);
    return (super.onCreateOptionsMenu(menu));
}

The error message I get:

解决方案

try this,

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


And in onCreate add this line to make the options appear in your Toolbar

setHasOptionsMenu(true);

这篇关于onCreateOptionsMenu内片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 20:34