【问题标题】:Changing SearchView color of back and clear icon in Android Toolbar更改 Android 工具栏中后退和清除图标的 SearchView 颜色
【发布时间】:2015-11-21 21:09:18
【问题描述】:

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

解决方案 1:

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

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

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

【问题讨论】:

  • 你是否尝试过覆盖drawerToggle
  • @Ramesh 感谢您的回复。请检查我的更新答案
  • 主题扩展 Theme.AppCompat.Light 背后的原因是什么

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


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    我假设您使用它作为您的基本应用程序主题。

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

    改成

    <style name="AppTheme" parent="@style/Theme.AppCompat.NoActionBar">
    

    如果您只想将后退和 X 图标更改为白色,这对我有用。

    【讨论】:

      【解决方案3】:

      1:要更改返回按钮图标,请添加

      app:collapseIcon="@drawable/back_arrow"
      

      android.support.v7.widget.Toolbar

      2:要更改清除按钮图标,请添加

      ImageView searchClose = searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
      searchClose.setImageResource(R.drawable.close);
      

      onCreateOptionsMenu

      【讨论】:

        猜你喜欢
        • 2016-04-07
        • 1970-01-01
        • 2019-03-11
        • 2017-07-09
        • 2016-01-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-04
        相关资源
        最近更新 更多