问题描述
我一直在尝试添加一个按钮SherlockActionBar,但我无法得到它的工作。
I have been trying to add a button to the SherlockActionBar but I can't get it working.
这是在code,我有:
This is the code that I have:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
android.view.MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, (android.view.Menu) menu);
return super.onCreateOptionsMenu(menu);
}
这是我的 menu.xml文件
code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/save_button"
android:title="i"
android:showAsAction="always" />
</menu>
这是不行的,因为即使我preSS菜单按钮,什么也不显示。有没有其他办法?难道我做任何错误?
This doesn't work, as even if I press the menu button, nothing shows up.Is there any other way? Am I making any mistake?
推荐答案
您使用的是Android的菜单和MenuInflater,而应使用附带ActionBarSherlock类:
You are using Android's Menu and MenuInflater, but should be using the classes that come with ActionBarSherlock:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.menu, (com.actionbarsherlock.view.Menu) menu);
return super.onCreateOptionsMenu(menu);
}
好像你在交织两个现在。请确保您只导入com.actionbarsherlock.view.Menu和com.actionbarsherlock.view.MenuInflater,而不是其Android同行。我建议你做类似如下:
It seems like you are intermingling the two right now. Make sure that you import only com.actionbarsherlock.view.Menu and com.actionbarsherlock.view.MenuInflater, and not its Android counterparts. I recommend you to do something like the following:
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
...
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
这篇关于添加一个按钮,与ActionBarSherlock的动作条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!