我有一个菜单,但我只获得了操作栏中显示的三个菜单项中的两个。我认为这是空间问题,因为如果我重新排序xml文件中的项目,我总是得到前两项。如何获得更多空间来显示所有三个项目?
菜单项的部分活动:
....... @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_catagory, menu);
return super.onCreateOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
break;
case R.id.action_favorite:
Intent i = new Intent(MapActivity.this, FavouriteListActivity.class);
startActivity(i);
break;
case R.id.action_catagory:
Intent intent = new Intent(MapActivity.this, NearByPlacesActivity.class);
startActivity(intent);
break;
case R.id.action_check:
Intent u = new Intent(MapActivity.this, ChackinListActivity.class);
startActivity(u);
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
}.........
带有菜单项的.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_check"
android:icon="@drawable/check"
android:title="@string/action_check"
yourapp:showAsAction="ifRoom|withText" />
<item android:id="@+id/action_favorite"
android:icon="@drawable/favourite"
android:title="@string/action_favorite"
yourapp:showAsAction="ifRoom|withText" />
<item
android:id="@+id/action_catagory"
android:icon="@drawable/search"
android:title="@string/action_catagory"
yourapp:showAsAction="ifRoom|withText"/>
</menu>
答案 0 :(得分:0)
我可能在这里错过了一些内容,但在每个MenuItem中都不会yourapp:showAsAction="always"
而不是yourapp:showAsAction="ifRoom|withText"
来解决这个问题?