我正在关注developer.android.com上的教程,并尝试在操作栏上添加项目。操作按钮不显示在操作栏上?
尽管我添加了搜索操作显示的所有代码,但是显示为溢出元素而不是操作按钮元素。我尝试了使用软键盘选项的4“和7”虚拟设备。
这里是
main_activity_actions.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:showAsAction="never" />
</menu>
这里是MainActivity.java
的onCreateOptionsMenu
方法。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
我想了解是什么原因导致这个问题。
你能提供的截屏与溢出可见? –
这看起来不像这个问题的重复... – adamdport