How to remove white underline in a SearchView widget in Toolbar Android

后端 未结 10 2015
挽巷
挽巷 2020-12-01 03:33

I am using Toolbar search widget in my project. Everything works fine but expect the thing which I am completely stuck up with removing the underline below search field in m

相关标签:
10条回答
  • 2020-12-01 04:00

    If you are using SearchView then use for API below 21

    android:queryBackground="@android:color/transparent"
    

    you can use below code if you are using API 21 or more

    app:queryBackground="@android:color/transparent"
    
    0 讨论(0)
  • 2020-12-01 04:01

    Once try as follows

    View v = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
    v.setBackgroundColor(Color.parseColor("here give actionbar color code"));
    

    Hope this will helps you.

    0 讨论(0)
  • 2020-12-01 04:03

    Or you can do this through styles:

    <style name="SearchViewMy" parent="Widget.AppCompat.Light.SearchView">
        <item name="submitBackground">@color/primaryColor</item>
        <item name="queryBackground">@color/primaryColor</item>
    </style>
    

    queryBackground is attribute for the query background. If you support voice search you may want to remove the line also under that mic button. Thats what submitBackground attribute is for.

    Then of course apply the style to your theme.

    <style name="Theme.App" parent="Theme.AppCompat.Light.NoActionBar.FullScreen">
        <item name="searchViewStyle">@style/SearchViewMy</item>
    </style>
    
    0 讨论(0)
  • 2020-12-01 04:09

    For androidx and kotlin:

            menuInflater.inflate(R.menu.conversation_list_screen_menu, menu)
            val searchItem = menu.findItem(R.id.action_search)
            searchView = searchItem.actionView as SearchView
            searchView?.findViewById<View>(androidx.appcompat.R.id.search_plate)?.setBackgroundColor(Color.TRANSPARENT)
    
    0 讨论(0)
提交回复
热议问题