【问题标题】:ActionBarSherlock getMenuInflater issuesActionBarSherlock getMenuInflater 问题
【发布时间】:2012-04-17 09:57:31
【问题描述】:

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

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

因此,看起来定义正在选择 ABS 版本的 menu inflater,但 getMenuInflater() 方法返回的是基本 Android 版本。代码如下:

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

谁能告诉我我在这里做错了什么?将不胜感激!

【问题讨论】:

    标签: android actionbarsherlock


    【解决方案1】:

    尝试将getMenuInflater() 更改为getSupportMenuInflater()

    【讨论】:

    • 如果这是在Fragment 内,您需要调用getSherlockActivity().getSuportMenuInflater() 或通过getActivity() 适当地转换它,即...(SherlockActivity)getActivity()...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多