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?
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.
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.
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With