我想向操作栏添加一个操作,但它在我的操作栏中显示为下拉列表。 如何将按钮添加到操作栏? 我的代码是:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="Add"
showAsAction="ifRoom"/>
</menu>
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
最佳答案
如果您正在使用 android.app.Activity
,只需将 showAsAction="always"
更改为 "android:showAsAction="always"
。
如果您使用的是 android.support.v7.app.Activity
,请按如下方式更改代码:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="Add"
app:showAsAction="ifRoom"/>
</menu>
关于android - 向操作栏面板添加操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22780234/