gpt4 book ai didi

安卓 : Search Icon not showing on Action Bar

转载 作者:太空宇宙 更新时间:2023-11-03 10:18:41 24 4
gpt4 key购买 nike

正如标题所说,我试图在我的操作栏中添加一个图标(用于搜索目的),但我得到的只是三点菜单中的项目标题。这是我使用的代码。

menu_main.xml :

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">

<item android:id="@+id/action_search"
android:icon="@drawable/search"
android:orderInCategory="100"
android:title="action_search"
app:showAsAction="always"/>
</menu>

我展开菜单的方式:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

if (id == R.id.action_search) {
return true;
}

return super.onOptionsItemSelected(item);
}

你们知道为什么会这样吗?

PS:我将 holo.light 作为我应用的默认主题。

最佳答案

您正在为 native 操作栏使用一些东西(例如,从 FragmentActivity 继承)和一些用于 appcompat-v7 操作栏反向移植的东西(例如,app:showAsAction).

menu_main.xml 更改为:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">

<item
android:id="@+id/action_search"
android:icon="@drawable/search"
android:orderInCategory="100"
android:showAsAction="always"
android:title="action_search" />
</menu>

关于安卓 : Search Icon not showing on Action Bar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29948051/

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