How to disable the search?

Can you help me on how to turn off the search when a button is clicked? I am trying this code:

searchView.setEnabled(false); searchView.setFocusableInTouchMode(false); searchView.clearFocus(); 

but it does not seem to work. I can still enter text in searchview.

Thanks..:))

+3
source share
10 answers

You can use:

 searchView.clearFocus(); 

and if you want to hide it using:

 searchView.setVisibility(View.GONE); 
+5
source

All of the above questions do not work for me. Becase SearchView is a ViewGroup, so we must disable all of its child views.

 private void enableSearchView(View view, boolean enabled) { view.setEnabled(enabled); if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; for (int i = 0; i < viewGroup.getChildCount(); i++) { View child = viewGroup.getChildAt(i); enableSearchView(child, enabled); } } } 

Elsewhere, call it:

 enableSearchView(searchView, true/false); 
+2
source

Try the following:

 searchview.setInputType(InputType.TYPE_NULL); 
+1
source

SearchView is not the text that you enter into the text of the EditText, but rather the LinearLayout, which contains a bunch of views, including the text of the edit.

To get an idea that you really want to turn off, follow these steps:

 EditText searchViewEditText = (EditText) searchView.findViewById(R.id.search_src_text); 

Please note: this only works if you use v7 search support, as the specific resource identifier is internal if you use the view-based view.

+1
source

Try searchView.setIconified (true);

+1
source

You tried

searchView.setVisibility(View.GONE); ?

0
source

If you want to clear it (SearchView), follow these steps:

searchView.clearFocus();

and if you want to temporarily hide it, do:

searchView.setVisibility(View.GONE);

0
source

It worked for me

 ImageView searchIcon = (ImageView)searchView.findViewById(android.support.v7.appcompat.R.id.search_button); searchIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Don't perform any action. } }); 
0
source
 searchView.findViewById(R.id.search_button).setEnabled(false); 

But you have to check it for null and hide the searchView:

 ImageView searchBtn = (ImageView) searchView.findViewById(R.id.search_button); if (searchBtn != null) searchBtn.setEnabled(false); searchView.setVisibility(View.GONE); 

I think it will work

0
source
 searchView.setOnQueryTextFocusChangeListener( new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if(hasFocus && !v.isEnabled()) v.clearFocus(); } } 
0
source

All Articles