android 栏 Sherlock 添加按钮
再次,我在这里使用操作栏夏洛克时不知所措..似乎我添加的按钮根本没有出现。 中所做的操作,
这是我已经在清单
<activity android:name=".RecipeBookList" android:theme="@style/SherlockCustom"></activity>
、styles.xml 和 RecipeBookList.java
<style name="SherlockCustom" parent="@style/Theme.Sherlock.Light">
<item name="abHeight">25dip</item>
<item name="abBackground">#ffffff</item>
<item name="abDisplayOptions">useLogo|showHome|homeAsUp|showTitle</item>
</style>
以及
public class RecipeBookList extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recipebooklist);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//Toast.makeText(RecipeBookList.this, "" + position, Toast.LENGTH_SHORT).show();
displayRecipeList(""+position);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.mainmenu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Toast.makeText(this, "Just a test", Toast.LENGTH_SHORT).show();
return true;
}
mainmenu.xml
<item android:id="@+id/preferences" android:title="Search" android:showAsAction="always|withText" android:icon="@drawable/ab_search"></item>
但搜索按钮根本没有出现在操作栏中。事实上,它没有出现在任何地方根本不。我哪里错了?
again, i'm at loss using action bar sherlock here.. it seems the button I added doesn't appear at all. here's what i already did
in my manifest
<activity android:name=".RecipeBookList" android:theme="@style/SherlockCustom"></activity>
and in my styles.xml
<style name="SherlockCustom" parent="@style/Theme.Sherlock.Light">
<item name="abHeight">25dip</item>
<item name="abBackground">#ffffff</item>
<item name="abDisplayOptions">useLogo|showHome|homeAsUp|showTitle</item>
</style>
and in my RecipeBookList.java
public class RecipeBookList extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recipebooklist);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//Toast.makeText(RecipeBookList.this, "" + position, Toast.LENGTH_SHORT).show();
displayRecipeList(""+position);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.mainmenu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Toast.makeText(this, "Just a test", Toast.LENGTH_SHORT).show();
return true;
}
aind in my mainmenu.xml
<item android:id="@+id/preferences" android:title="Search" android:showAsAction="always|withText" android:icon="@drawable/ab_search"></item>
but the search button doesn't appear in the action bar at all.. in fact it doesn't appear anywhere at all. where did i went wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用此处提供的片段支持包:http://beta.abs.io/
然后修复您的导入以使用 ActionBarSherlock 等效项,并使用 getSupportMenuInflater() 而不是 getMenuInflater()
编辑:可能应该提到,这是如果您使用的是 ABS4。
You need to use the fragment support package provided here: http://beta.abs.io/
Then fix your imports to use the ActionBarSherlock equivelants, and use getSupportMenuInflater() instead of getMenuInflater()
Edit: Should probably mention, this is if you are using ABS4.
尝试使用这个
你也可以在他们的页面和APK中使用示例,你可以在这里检查它的代码:
https://github.com/JakeWharton/ActionBarSherlock/blob/master/samples/demos/src/com/actionbarsherlock/sample/demos/ActionItems.java
try to use this
Also you have in their page and APK with samples and you can check its code here:
https://github.com/JakeWharton/ActionBarSherlock/blob/master/samples/demos/src/com/actionbarsherlock/sample/demos/ActionItems.java