How To Disable Searchview?
Can you help me on how to disable searchview when button is pressed? I'm trying this code: searchView.setEnabled(false); searchView.setFocusableInTouchMode(false);
Solution 1:
All above questions don't work for me. Becase SearchView is a ViewGroup, so we have to disable all its child views.
privatevoidenableSearchView(View view, boolean enabled) {
view.setEnabled(enabled);
if (view instanceof ViewGroup) {
ViewGroupviewGroup= (ViewGroup) view;
for (inti=0; i < viewGroup.getChildCount(); i++) {
Viewchild= viewGroup.getChildAt(i);
enableSearchView(child, enabled);
}
}
}
In other place, call this:
enableSearchView(searchView, true/false);
Solution 2:
You can use:
searchView.clearFocus();
and if you want to hide it using:
searchView.setVisibility(View.GONE);
Solution 3:
Try the following:
searchview.setInputType(InputType.TYPE_NULL);
Solution 4:
SearchView
isn't the actual EditText
you type into, but rather is a LinearLayout
which holds a bunch of views, including the EditText
.
To get the view you actually want for disabling it:
EditTextsearchViewEditText= (EditText) searchView.findViewById(R.id.search_src_text);
Note, this only works if you're using support v7 SearchView
, since the particular resource id is internal if you use the framework SearchView
.
Solution 5:
searchView.findViewById(R.id.search_button).setEnabled(false);
But you must check it for null and hide searchView:
ImageViewsearchBtn= (ImageView) searchView.findViewById(R.id.search_button);
if (searchBtn != null) searchBtn.setEnabled(false);
searchView.setVisibility(View.GONE);
I think this will work
Post a Comment for "How To Disable Searchview?"