1

I have a button in an activity, on clicking that button, I direct the user to a search activity with a search view in the toolbar..

I'm using android.support.v7.widget.SearchView, I managed to expand it automatically using searchView.setIconifiedByDefault(false) in onCreateOptionsMenu.. I also open the keypad automatically in activity onCreate, yet I still have to click in the searchView to start typing there, I want the cursor to be set there automatically..

any help?

Omar Labib
  • 55
  • 9

1 Answers1

1

call setIconifiedByDefault(false) when the searchview is intialized.

Sets the default or resting state of the search field. If true, a single search icon is shown by default and expands to show the text field and other buttons when pressed. Also, if the default state is iconified, then it collapses to that state when the close button is pressed. Changes to this property will take effect immediately.

Try the below, it worked for me once.

   searchView.setIconifiedByDefault(true);
   searchView.setFocusable(true);
   searchView.setIconified(false);
   searchView.requestFocusFromTouch();

Update: If you are Using android.support.v7.widget.SearchView the behaviour is very different. clearFocus is needed if you don’t want the keyboard pop-up all the time.

Also in the searchview layout, use <requestFocus /> tag.

Remario
  • 3,813
  • 2
  • 18
  • 25