Disabling SearchView

I am trying to disconnect SearchView from my Activity . I tried the following code:

  mSearchView.setEnabled(false); mSearchView.setFocusable(false); mSearchView.setClickable(false); 

But that will not work. SearchView can still be clicked and a KeyBoard will appear. I want it to turn gray and ugly. How can i do this?

+4
source share
5 answers

None of the above answers were sufficient for my needs, so I would like to provide another one for anyone in the same situation.

SearchView, has focus, has a search and clear button

SearchView consists of different views, which can be - and in this case should be - addressed individually. If you want your SearchView (v7 support) to freeze and sit in that state without responding to any input, including the search and clear button, you can use:

 ImageView clearButton = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn); SearchView.SearchAutoComplete searchEditText = (SearchView.SearchAutoComplete) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); clearButton.setEnabled(false); searchEditText.setEnabled(false); searchView.setSubmitButtonEnabled(false); 

(Also, I had a problem with the deeptis answer searchView.setInputType searchView.setInputType(InputType.TYPE_NULL) : if you disable SearchView this way and then click on it, the system seems to expect an open keyboard, although the keyboard does not appear. Therefore, the first return button click causes nothing but closing — not shown or not open — the keyboard.)

+5
source

To disable any view (e.g. SearchView ), set its input-type to none in XML format or call view.setInputType(InputType.TYPE_NULL) from Activity .

+4
source

You can also completely hide the searchView. You can hide searchview and searchicon by doing the following:

  searchItem.setVisible(false); searchView.setVisibility(View.GONE); 

Then you can return it:

  searchItem.setVisible(true); searchView.setVisibility(View.VISIBLE); 
+1
source

Clear search focus Search:

 searchView.clearFocus(); 

Hide SearchView:

 searchView.setVisibility(View.GONE); 
0
source

From @outta comfort answer, here is my solution:

 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); 
0
source

All Articles