gpt4 book ai didi

android - 如何在android中自定义工具栏上的搜索图标?

转载 作者:行者123 更新时间:2023-11-29 19:55:32 24 4
gpt4 key购买 nike

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:appcompat="http://schemas.android.com/apk/res-auto"
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"
appcompat:actionViewClass="android.support.v7.widget.SearchView"
appcompat:showAsAction="ifRoom"
android:title="Search"/>
</menu>

我想更改 search image右上角,目前是黑色,我想改成橙色

最佳答案

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_notifications, menu);
this.menu = menu;
super.onCreateOptionsMenu(menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_clear_all) {
showToast("Clear All");
return true;
}
return super.onOptionsItemSelected(item);
}

在res>菜单下创建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=".YourActivityName" >

<item
android:id="@+id/action_clear_all"
android:title="@string/noti_clear_all"
android:icon="@drawable/ic_clear_all"
android:orderInCategory="100"
app:showAsAction="ifRoom" />

</menu>

关于android - 如何在android中自定义工具栏上的搜索图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36763462/

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