ActionBarSherlock getMenuInflater问题

Ned*_*nin 36 android actionbarsherlock

我最近参加了ABS4.0潜水.但是,我似乎在使用MenuInflater时出现问题.

当使用getMenuInflater()方法时,我收到一条错误消息,指出:"类型不匹配:无法从android.view.MenuInflater转换为com.actionbarsherlock.view.MenuInflater"

因此,看起来定义正在获取菜单inflater的ABS版本,但getMenuInflater()方法返回基本Android版本.代码如下:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return super.onCreateOptionsMenu(menu);
}
Run Code Online (Sandbox Code Playgroud)

谁能告诉我这里做错了什么?非常感谢!

Sea*_*eil 113

尝试getMenuInflater()改为getSupportMenuInflater()

  • 如果这是在`Fragment`中你需要调用`getSherlockActivity().getSuportMenuInflater()`或者通过`getActivity()`来适当地转换它... ie ...`(SherlockActivity)getActivity()...` (5认同)