【问题标题】:Need to change SearchView cursor color and underline color to white in android需要在android中将SearchView光标颜色和下划线颜色更改为白色
【发布时间】:2016-09-28 09:19:40
【问题描述】:

我需要帮助将 SearchView 光标颜色和下划线颜色更改为白色。下面是我的代码

            <SearchView
            android:id="@+id/search"
            style="@style/CustomSearchView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:closeIcon="@drawable/ic_close_white"
            android:gravity="bottom"
            android:iconifiedByDefault="false"
            android:queryHint="@string/search_store"
            android:searchHintIcon="@null" />

<style name="CustomSearchView" parent="MyMaterialTheme">
    <item name="android:textSize">6sp</item>
    <item name="submitBackground">@android:color/transparent</item>
    <item name="queryBackground">@android:color/transparent</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:textColorHint">@color/label_input_color</item>
    <item name="android:textCursorDrawable">@drawable/cursor</item>
    <item name="colorControlActivated">@android:color/white</item>
</style>

请帮忙。

【问题讨论】:

    标签: android android-layout android-studio android-fragments


    【解决方案1】:

    要更改搜索查询下方线条的颜色,请尝试在您的 CustomSearchView 样式中定义 backgroundTint:

    具有向后兼容性支持:

    &lt;item name="backgroundTint"&gt;@color/colorWhite&lt;/item&gt;

    如果不起作用,请尝试不支持向后兼容性:

    &lt;item name="android:backgroundTint"&gt;@color/colorWhite&lt;/item&gt;

    但是,这个解决方案并不完美,因为它引用了其他 searchView 元素。

    【讨论】:

      【解决方案2】:

      改变下划线颜色

          View searchplate = (View)searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
          searchplate.getBackground().setColorFilter(Color.DKGRAY, PorterDuff.Mode.MULTIPLY);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-02-07
        • 2012-09-15
        • 2011-12-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多