Search code examples
androidandroid-edittextsearchview

Request focus on expanding android searchview v7


If I click the search icon on android app I want to auto focus the EditText of the searchview.

If I click on the search icon it expands the searchview (support.v7) and opens the soft input keyboard. But the cursor isn't set to the EditText so if I type something nothing is happening until I click on the EditText manually.

How can I set the focus to the EditText after clicking the search icon?

I tested searchview.setFocusable(true); but it isn't working ...

(tested on Galaxy Tab with Android 5 and Galaxy S6 with Android 5)

Thank you very much!


Solution

  • Thanks to Brandon!

    Whole solution:

            searchView.setOnSearchClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    searchView.requestFocus();
                }
            });