简体   繁体   中英

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!

try searchview.requestFocus()

Right now since you're only using setFocusable(true), you're basically just telling the device that your searchview can focus, not actually focusing on it.

Thanks to Brandon!

Whole solution:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM