如何更改SearchView元素的颜色? [英] How to change SearchView elements' color?

查看:107
本文介绍了如何更改SearchView元素的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在项目中使用SearchView,但是元素的颜色有问题.让我向您展示:我的SearchView所在的fragmentDialog

我不需要更改bg颜色.例如下一张图片.我想查看没有黑色背景的SearchView元素.

我试图

I want to use SearchView in my project, but I have a problem with elements' color. Let me show you: its fragmentDialog where I have my SearchView

I dont need to change bg color. The next picture is for example. I want to see SearchView elements without black bg.

I have tried to

  • 更改主题
  • 更改样式
  • 更改色调

,但没有任何效果.搜索图标和注释器元素仍为白色.也许我正在失去一些东西?我可以用XML做到这一点吗?请帮帮我.

but nothing is working. The search icon and anoter elements still white. Maybe I'm losing something? Can I do this in XML? Please, help me.

推荐答案

您需要在搜索视图中以这种样式使用android.support.v7.widget.SearchView

尝试

You need to use android.support.v7.widget.SearchView

try with this style in your searchview,

在扩展搜索视图之前--->

Before expanding searchview --->

展开搜索视图后--->

After expanding searchview --->

<android.support.v7.widget.SearchView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/search_view"
            style="@style/SearchViewStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            android:layout_gravity="end" />

<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView">
    <!-- Gets rid of the search icon -->
    <item name="searchIcon">@drawable/ic_search</item>
    <!-- Gets rid of the "underline" in the text -->
    <item name="queryBackground">@color/white</item>
    <!-- Gets rid of the search icon when the SearchView is expanded -->
    <item name="searchHintIcon">@null</item>
    <!-- The hint text that appears when the user has not typed anything -->
    <item name="queryHint">@string/search_hint</item>
</style>

这篇关于如何更改SearchView元素的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆