自动展开并聚焦于 SearchView [英] Expand and give focus to SearchView automatically

查看:16
本文介绍了自动展开并聚焦于 SearchView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,用户在其中按下 ActionBar 中的搜索"图标,并且 SearchView 在屏幕顶部可见.

I'm developing an application where the user presses the "Search" icon in the ActionBar and a SearchView is made visible at the top of the screen.

我的问题是 SearchView 既未聚焦也未展开,因此用户必须按下 Searchview 上的搜索按钮以使其展开并显示键盘.

My problem is that the SearchView is not in focus nor expanded so the user has to press the search button on the Searchview to make it expand and bring out the keyboard.

应该如何解决?

推荐答案

要使 SearchView 默认展开,请调用 setIconifiedByDefault(false) 当你初始化它时(例如在 onCreateOptionsMenu(..)onPrepareOptionsMenu(..)>).我发现在大多数情况下这会自动给它焦点,但如果不是简单地调用 requestFocus() 也可以.

To make the SearchView expanded by default, call setIconifiedByDefault(false) on it when you initialise it (e.g. in onCreateOptionsMenu(..) or onPrepareOptionsMenu(..)). I've found in most cases this will give it focus automatically, but if not simply call requestFocus() on it too.

这篇关于自动展开并聚焦于 SearchView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆