SearchView在片段中(非工具栏中)无法删除下划线
问题描述:
在我的片段中,我使用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"));
但强调没有帮助。 这里截图:
答
程序兼容性提供了搜索查看两种风格:
- 用下划线
- 一个操作栏使用默认不带有下划线
你可以这样改变风格:
<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>
你可以直接使用属性,当然。
尝试将'searchview'设置为null(适用于'AutoCompleteTextView')。 –
@LalitSinghFauzdar SearchView实际上是一个LinearLayout,并且它的背景设置在EditText里面,所以这是行不通的。 –
android:background =“@ null” - 没有帮助 – Alexei