Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android search widget How to hide the close button in search view by default?

I have implemented an android SearchView in ActionBar. When the SearchView gains focus, the close button [x] at the right shows up. I took a look at other android native apps, like Contacts and Gmail. The close button is not shown when the SearchView gains focus.

How to set my SearchView behave like that?

like image 902
sunny Avatar asked Sep 19 '14 09:09

sunny


People also ask

What is SearchView in android?

android.widget.SearchView. A widget that provides a user interface for the user to enter a search query and submit a request to a search provider. Shows a list of query suggestions or results, if available, and allows the user to pick a suggestion or result to launch into.

How do I put the search bar on my Android ToolBar?

As we have already implemented SearchView widget over activity layout, it can also be implemented over ToolBar/ActionBar. For implementing SearchView over ToolBar, we need to create menu option and place SearchView widget on it.


1 Answers

Posting for future visitors. Previous answers are old and not easy. All you have to do is to set null to app:closeIcon this way app:closeIcon="@null"

  <androidx.appcompat.widget.SearchView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:closeIcon="@null"   <!-- This simple solution -->
    app:iconifiedByDefault="false" />
like image 106
Taseer Ahmad Avatar answered Sep 24 '22 06:09

Taseer Ahmad