Search code examples
androidsearchview

Disable SearchView icons from changing


I have a SearchView that is starting a new fragment. However, every time I'm back pressing from the fragment, my searchView is showing the EditText field, and the mic button.

Can I have my SearchView be able to start my new fragment (meaning that it's clickable) but without changing any view of the SearchView.

After coming back to my SearchView from my Fragment:

I would like to see this:

enter image description here

And Not the following:

enter image description here


Solution

  • I found an answer to my thread question. I would like to share it just in case someone else needs it:

    I have put the following code in my onCreateView method

                searchView = (SearchView) mToolBar.findViewById(R.id.searchView);
                searchView.setIconifiedByDefault(false);
                searchView.setQueryHint("");
    
                SearchView.SearchAutoComplete searchIconText = (SearchView.SearchAutoComplete)
                        searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
                searchIconText.setVisibility(View.GONE);