如何从Android SearchView组件中删除底部线?

12
如何在Android SearchView组件中去除底部线条?就像这张图片中的一样:

enter image description here


1
你可以参考这个链接:https://dev59.com/iF0Z5IYBdhLWcg3w-UZ-它可能对在Android工具栏中的SearchView小部件中移除白色下划线有所帮助。 - HarshitMadhav
谢谢,帮了我100%。 - yozhik
我很高兴能够帮助到你 :-) 干杯! - HarshitMadhav
7个回答

28
<androidx.appcompat.widget.SearchView
  app:queryBackground="@null"
  ...
/>

将其设为 @null 可以在您的 XML 中删除彩色条。


5
当你获取到你的SearchView的引用时,这个方法就可以使用了:
val backgroundView = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate) as View
backgroundView.background = null

1
如果我想要自定义背景,同时又不想要下划线,你的答案就不适用了... - Siddharth Thakkar

4
如果你在SearchView的XML中使用了android命名空间,那么去除底部线条的最佳方法是:android:queryBackground="@null"

2
在layout.xml文件中。
<SearchView
    android:theme="@style/AppSearchView"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginHorizontal="16dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/round_corner_rect"
    android:queryBackground="@null"
    android:queryHint="Search here..."
    android:iconifiedByDefault="false" />

style.xml

 <style name="AppSearchView" parent="Widget.AppCompat.SearchView">
    <item name="android:editTextColor">@color/text_color</item>
    <item name="android:textColor">@color/text_color</item>
    <item name="android:textColorHint">@color/text_color</item>
    <item name="android:textSize">12sp</item>
    <item name="android:fontFamily">@font/app_font</item>
</style>

0

只需在xml中编写:

<androidx.appcompat.widget.SearchView
   android:id="@+id/searchView"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   app:queryBackground="@null"
   ... />

对我有用


0
使用:app:queryBackground="@color/your_color"android:background="@color/your_color"

0
尝试在搜索视图的xml中设置background="@null"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接