gpt4 book ai didi

java - 将光标设置为自动搜索 View

转载 作者:行者123 更新时间:2023-11-30 00:11:47 24 4
gpt4 key购买 nike

我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com