android - 更改 Android 工具栏中返回和清除图标的 SearchView 颜色

标签 android android-actionbar searchview android-toolbar android-appcompat

我想在 SearchView 折叠时自定义返回和清除图标。我的要求是将颜色更改为白色,但现在是黑色。(请引用下面共享的图片)。我希望用几天的时间来解决这个问题,但我尝试过的解决方案都没有奏效。我尝试了一些 SO 建议的解决方案,如下所示:

解决方案一:

<style name="AppTheme" parent="@style/Theme.Base.AppCompat.Light.DarkActionBar">
    <item name="actionBarWidgetTheme">@style/YourActionBarWidget</item>
</style>

<style name="YourActionBarWidget" parent="@style/Theme.AppCompat">
    <item name="searchViewCloseIcon">@drawable/xxx</item>
</style>

解决方案 2:

final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(getResources().getColor(R.color.WHITE), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);  

我的项目 styles.xml

<style name="ToolBarTheme" parent="@style/Theme.AppCompat.Light">
        <item name="colorPrimary">@color/blue</item>
        <item name="colorPrimaryDark">@color/blue</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
        <item name="android:itemTextAppearance">@style/myCustomMenuTextApearance</item>
        <item name="android:actionMenuTextColor">@color/white</item>
        <item name="actionMenuTextColor">@color/white</item>

    </style>



<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
        <item name="spinBars">true</item>
        <item name="color">@color/white</item>
        <item name="gapBetweenBars">2.5dip</item>
        <item name="thickness">2dp</item>
    </style>

我的确切问题的屏幕截图:

enter image description here

请帮助我解决我的问题。任何一种解决方案和建议都会对我有很大帮助。感谢您的支持。

最佳答案

如果您正在搜索工具栏上的白色图标 将这些添加到您的工具栏标签上

android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

关于android - 更改 Android 工具栏中返回和清除图标的 SearchView 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32250147/

相关文章:

Android 工具栏没有完全隐藏(> Lollipop)

java - 如何从 Activity 外部扩展 SupportActionBar 菜单

Android,如何在按下 "Back"按钮关闭searchView时关闭ListView

android - Searchview - 隐藏通过按键出现的 toast

使用简单的应用程序在 adb 上 android 进程崩溃,不知道我做错了什么

android - 很难为 Android 编译 tess-two

java - 使用 ActionBar 选项卡进行导航时菜单折叠

java - 实现自己的 Android CursorAdapter 用于搜索建议 - 未知异常

android - 有没有办法检索 MediaCodec 实例的限制?

java - 通过 Java 套接字发送多个文件