gpt4 book ai didi

android - 向操作栏面板添加操作

转载 作者:行者123 更新时间:2023-11-29 17:51:05 25 4
gpt4 key购买 nike

我想向操作栏添加一个操作,但它在我的操作栏中显示为下拉列表。如何将按钮添加到操作栏?我的代码是:

<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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com