Android ActionBarSherlock:getSupportMenuInflator()未定义
我正在使用ActionBarSherlock并试图通过使用Android ActionBarSherlock:getSupportMenuInflator()未定义,android,actionbarsherlock,Android,Actionbarsherlock,我正在使用ActionBarSherlock并试图通过使用getSupportMenuInflator()膨胀我的XML菜单,但它给出了一个错误: the method getSupportMenuInflator() is undefined for the type ... 我不明白它为什么会显示错误。代码如下: public void onCreateOptionsMenu(Menu menu) { getSupportMenuInflater().inflate(R.menu.
getSupportMenuInflator()
膨胀我的XML菜单,但它给出了一个错误:
the method getSupportMenuInflator() is undefined for the type ...
我不明白它为什么会显示错误。代码如下:
public void onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.activity_main, menu);
...
}
如何修复它?您需要使用:
getSherlockActivity().getSupportMenuInflater().inflate(R.menu.activity_main, menu);
因为
getSupportMenuInflater()
是SherlockActivity中的一个方法,而不是SherlockFragment。如果您使用的是SherlockActionBar,您应该实现SherlockActivity
,而不是Activity和getSupportMenuInflater()
将可用项目中是否包含ABS库?是的,这是我做的第一件事。好的。知道了。但是现在它给出了一个错误:类型MenuInflater中的方法inflate(int,Menu)不适用于参数(int,Menu)??您需要导入ABS菜单和MenuItem类:import com.actionbarsherlock.view.Menu代码>导入com.actionbarsherlock.view.MenuItem代码>不是Android版本。