[英]Android ActionBar not showing icons
I have seen this question asked many times, however, none of those solutions have helped me. 我已经多次看到这个问题,但是这些解决方案都没有帮助我。 My problem is that I have an ActionBar menu and I want its items to always be displayed on the ActionBar instead of the drop down menu. 我的问题是我有一个ActionBar菜单,我希望它的项目始终显示在ActionBar而不是下拉菜单上。
I have tried actions suchs as "ifRoom", "always", etc. and they still show only with text on the drop down menu. 我尝试了“ ifRoom”,“ always”等操作,但它们仍然只在下拉菜单中显示文字。
Menu: devotional_fragment_actions.xml 菜单:devotional_fragment_actions.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_previous"
android:icon="@drawable/ic_action_previous_item"
android:title="@string/previous_action"
app:showAsAction="always"/>
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_go_to_today"
android:title="@string/date_action"
app:showAsAction="always"/>
<item android:id="@+id/action_next"
android:icon="@drawable/ic_action_next_item"
android:title="@string/next_action"
app:showAsAction="always"/>
</menu>
On my fragment I have: 在我的片段上,我有:
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// action bar
inflater.inflate(R.menu.devotional_fragment_actions, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle item selection of action bar
switch (item.getItemId()) {
case R.id.action_search:
showDatePickerDialog();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
The menu works fine but is not displaying as I want it. 菜单工作正常,但未按我的期望显示。 Thanks 谢谢
In each item use android
namespace instead of app
. 在每个项目中,使用android
名称空间而不是app
。 You can even remove this namespace declaration xmlns:app="http://schemas.android.com/apk/res-auto"
. 您甚至可以删除此名称空间声明xmlns:app="http://schemas.android.com/apk/res-auto"
。
Try set it like in code below: 尝试在下面的代码中进行设置:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_previous"
android:icon="@drawable/ic_action_previous_item"
android:title="@string/previous_action"
android:showAsAction="always"/>
</menu>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.