ActionBarSherlock:getSupportMenuInflator()未定义 [英] ActionBarSherlock: getSupportMenuInflator() is undefined

查看:85
本文介绍了ActionBarSherlock:getSupportMenuInflator()未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ActionBarSherlock ,并尝试通过使用 getSupportMenuInflator()来膨胀XML菜单,但它给出了错误消息:

I'm using ActionBarSherlock and trying to inflate my XML menu by using getSupportMenuInflator(), but it is giving an error:

the method getSupportMenuInflator() is undefined for the type ...

我无法弄清为什么显示错误。这是代码:

I'm unable to figure out why it's showing the error. Here is the code:

public void onCreateOptionsMenu(Menu menu) {
    getSupportMenuInflater().inflate(R.menu.activity_main, menu);
    ...
}

如何解决?

推荐答案

您需要使用:

getSherlockActivity().getSupportMenuInflater().inflate(R.menu.activity_main, menu);

因为 getSupportMenuInflater()是SherlockActivity不是SherlockFragment。

Since getSupportMenuInflater() is a method in SherlockActivity not SherlockFragment.

这篇关于ActionBarSherlock:getSupportMenuInflator()未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆