Android SearchView OnFocusChangeListener: onFocusChange not called at all

I have a SearchView in Activity; when the user performs a search, a Fragment containing the search results adds to the same Activity.

Now I want that when you click the SearchView button (so it gets the focus and the user enters there), the Fragment already shown (containing the search results) should be dim / blurry.

So I tried setting OnFocusChangedListener for SearchView in the SearchView callback method for Fragment , but it doesn't seem to be called at all.

 final Activity myActivity = getActivity(); Log.i(TAG, "myActivity>"+myActivity.toString());//check SearchView mySearchView = (SearchView) myActivity.findViewById(R.id.searchActivity_searchView); Log.i(TAG, "mySearchView>"+mySearchView.toString());//check mySearchView.setOnFocusChangeListener(new OnFocusChangeListener() { @SuppressLint("NewApi") @Override public void onFocusChange(View v, boolean hasFocus) { Log.i(TAG, "onFocusChange OF OnFocusChangeListener IN SearchResultsFragment CALLED."); if (hasFocus) { myActivity.getWindow().setDimAmount(1.0f); } } }); 

Am I missing something? What do I need to do to call onFocusChanged when the user clicks and thus activates the SearchView to enter their search query into it?

Note. If all SSCCE code is required, please ask in the comments, I will send it.

+5
source share
1 answer

Sorry for the late answer, but I had the same problem and found this question during the search so that it could help other people.

Have you tried using mySearchView.setOnQueryTextFocusChangeListener() instead of mySearchView.setOnFocusChangeListener() ?

Worked for me.

+23
source

Source: https://habr.com/ru/post/1211084/


All Articles