how to change android SearchView text

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.

searchView.setText(searchToken);

在想知道并尝试之后,我发现API中有一个名为setQuery()的方法,您可以设置searchView文本,并且您可以选择提交搜索或不使用布尔参数。

searchView.setQuery(searchToken, false);

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();

尝试这个:

searchView.setQueryHint("Search exchange...");
链接地址: http://www.djcxy.com/p/92942.html

上一篇: 创建一个看起来像材料设计指南的SearchView

下一篇: 如何更改android的SearchView文本