我在 Activity 中有一个按钮,单击该按钮后,我会将用户定向到工具栏中带有搜索 View 的搜索 Activity 。
我正在使用 android.support.v7.widget.SearchView
,我设法使用 onCreateOptionsMenu< 中的
..
我还在 searchView.setIconifiedByDefault(false)
自动展开它onCreate
Activity 中自动打开键盘,但我仍然必须在 searchView 中单击以开始在那里输入,我希望光标自动设置在那里..
有什么帮助吗?
最佳答案
调用setIconifiedByDefault(false)
当搜索 View 被初始化时。
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.
试试下面的方法,它对我有用过一次。
searchView.setIconifiedByDefault(true);
searchView.setFocusable(true);
searchView.setIconified(false);
searchView.requestFocusFromTouch();
更新:如果您正在使用 android.support.v7.widget.SearchView
行为非常不同。 clearFocus
如果您不想一直弹出键盘,则需要。
Also in the searchview layout, use
<requestFocus />
tag.
关于java - 将光标设置为自动搜索 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48039659/