片段中的SearchView(非工具栏中)无法删除下划线

时间:2017-10-16 16:56:20

标签: android android-layout searchview

在我的片段中,我使用searchView(不在工具栏中)。 我的布局代码段:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.SearchView
        android:id="@+id/searchView"
        android:layout_width="0dp"
        android:layout_height="30dp"
        android:layout_marginEnd="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        app:queryHint="Some hint"
        android:layout_marginStart="20dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:searchHintIcon="@null" />
</android.support.constraint.ConstraintLayout>

在我的片段代码中:

        searchView = view.findViewById(R.id.searchView);
        SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        searchView.setSuggestionsAdapter(new SearchCatalogSuggestionsAdapter(getActivity()));
searchView.setBackgroundColor(Color.parseColor("#FFFFFF"));

如你所见,我试试

searchView.setBackgroundColor(Color.parseColor("#FFFFFF"));

但强调并没有帮助。 这里截图:

Search-view-underline

1 个答案:

答案 0 :(得分:2)

AppCompat为SearchView提供两种样式:

  • 带下划线的默认值
  • 一个用于没有下划线的操作栏

你可以改变这样的风格:

<android.support.v7.widget.SearchView
    style="@style/Widget.AppCompat.SearchView.ActionBar"/>

样式如下:

<style name="Widget.AppCompat.SearchView.ActionBar" parent="Base.Widget.AppCompat.SearchView.ActionBar"/>

<style name="Base.Widget.AppCompat.SearchView.ActionBar">
    <item name="queryBackground">@null</item>
    <item name="submitBackground">@null</item>
    <item name="searchHintIcon">@null</item>
    <item name="defaultQueryHint">@string/abc_search_hint</item>
</style>

当然,您可以直接使用这些属性。

相关问题