1

我一直在尝试使用 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;

提前致谢。

4

1 回答 1

2

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

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

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

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

 return true;

        }
于 2013-05-06T09:18:32.633 回答