Reputation: 222
How can I remove the cancel button in the search bar on Android?
Upvotes: 0
Views: 229
Reputation: 6641
A simple approach could be:
<android.support.v7.widget.SearchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/searchView"
app:closeIcon="@null"/>
If you need to disable its function, try to achieve it using code behind:
Android.Support.V7.Widget.SearchView searchView = FindViewById<Android.Support.V7.Widget.SearchView>(Resource.Id.searchView);
ImageView mCloseButton = (ImageView)searchView.FindViewById(Resource.Id.search_close_btn);
mCloseButton.Enabled = false;
mCloseButton.SetImageDrawable(null);
We need to use Android.Support.V7.Widget.SearchView
here for retrieving the button or it will get null when using SearchView
.
I uploaded a simple sample here: https://github.com/landl0526/SearchViewSample.git
Here is the effect:
Upvotes: 1