在actionbarsherlock android中无法识别getSupportMenuInflater()和getSherlockActivity()

时间:2013-05-04 08:52:14

标签: android actionbarsherlock

我一直在尝试使用actionbarsherlock来扩充菜单,但没有运气。请提出错误的建议。 这是我的代码:

 @Override
        public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {

            MenuInflater inflater=getSherlockActivity().getSupportMenuInflater(); //getSherlockActivity() not recognised
inflater.inflate(R.menu.widgets_menu, menu);

  // I have also tried this:
//MenuInflater inflater=getSupportMenuInflater();// getSupportMenuInflater() not recognized
//inflater.inflate(R.menu.widgets_menu, menu);

 return true;

        }

注意:我已导入所有必要的类

import com.actionbarsherlock.ActionBarSherlock;
import com.actionbarsherlock.ActionBarSherlock.OnCreateOptionsMenuListener;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;

提前致谢。

1 个答案:

答案 0 :(得分:2)

终于得到了答案。感谢@petrch。

我刚刚将我的活动课程扩展到了Sherlock Activity。

@Override
        public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {

            MenuInflater inflater=getSherlockActivity().getSupportMenuInflater(); 
inflater.inflate(R.menu.widgets_menu, menu);

 return true;

        }