我要添加一个动作的操作栏,但它出现在我的行动吧作为一个下拉列表。 如何添加按钮的操作栏? 我的code是:
<菜单的xmlns:机器人=http://schemas.android.com/apk/res/android>
<项目机器人:ID =@ + ID / ACTION_SEARCH
机器人:图标=@可绘制/ ic_action_search
机器人:标题=添加
showAsAction =ifRoom/>
< /菜单>
@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
//充气菜单;这增加了项目操作栏,如果它是present。
MenuInflater充气= getMenuInflater();
inflater.inflate(R.menu.main,菜单);
返回super.onCreateOptionsMenu(菜单);
}
解决方案
如果您使用的是 android.app.Activity
只需修改 showAsAction =始终以
到机器人:showAsAction =总是
如果您使用的是 android.support.v7.app.Activity
修改code如下:
<菜单的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto>
<项目机器人:ID =@ + ID / ACTION_SEARCH
机器人:图标=@可绘制/ ic_action_search
机器人:标题=添加
应用程序:showAsAction =ifRoom/>
< /菜单>
I want to add an action to the action bar, but it appears in my action bar as a drop down list. How can I add button to the action bar? My code is:
<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);
}
解决方案
If you are using android.app.Activity
simply change showAsAction="always"
to "android:showAsAction="always"
.
If you are using android.support.v7.app.Activity
change the code as follows:
<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>
上一篇:java.lang.NoClassDefFoundError的:在的javax.activation.DataHandler机器人机器人、NoClassDefFoundError、lang、jav
下一篇:preemptive基本验证与HttpURLConnection类?基本、preemptive、HttpURLConnection