我想向操作栏添加一个操作,但它在我的操作栏中显示为下拉列表。
如何向操作栏添加按钮?
我的代码是:
<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"
to "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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)