how to change android SearchView text

前端 未结 5 2241

Is there a setText() method for SearchView or something like that? I try to set the search text in the searchView like this but there is no method for like this.

<         


        
5条回答
  •  -上瘾入骨i
    2020-12-13 02:11

    You can use setQuery() to change the text in the textbox.

    However, setQuery() method triggers the focus state of a search view, so a keyboard will show on the screen after this method has been invoked.

    To fix this problem, just call searchView.clearFocus() after setQuery() method to unfocus it and the keyboard will not show on the screen.

    Example:

    String suggestWord = intent.getDataString();
    searchView.setQuery(suggestWord, false);
    searchView.clearFocus();
    

提交回复
热议问题