简体   繁体   English

请求专注于扩展android searchview v7

[英]Request focus on expanding android searchview v7

If I click the search icon on android app I want to auto focus the EditText of the searchview. 如果我在android应用程序上单击搜索图标,则要自动聚焦searchview的EditText。

If I click on the search icon it expands the searchview (support.v7) and opens the soft input keyboard. 如果单击搜索图标,它将展开搜索视图(support.v7)并打开软输入键盘。 But the cursor isn't set to the EditText so if I type something nothing is happening until I click on the EditText manually. 但是光标没有设置为EditText,因此,如果我键入任何内容,则直到我手动单击EditText时都没有任何反应。

How can I set the focus to the EditText after clicking the search icon? 单击搜索图标后如何将焦点设置到EditText?

I tested searchview.setFocusable(true); 我测试了searchview.setFocusable(true); but it isn't working ... 但它不起作用...

(tested on Galaxy Tab with Android 5 and Galaxy S6 with Android 5) (在装有Android 5的Galaxy Tab和装有Android 5的Galaxy S6上测试)

Thank you very much! 非常感谢你!

try searchview.requestFocus() 尝试searchview.requestFocus()

Right now since you're only using setFocusable(true), you're basically just telling the device that your searchview can focus, not actually focusing on it. 现在,由于您仅使用setFocusable(true),因此您基本上只是在告诉设备您的搜索视图可以聚焦,而不是实际上聚焦于它。

Thanks to Brandon! 感谢布兰登!

Whole solution: 整体解决方案:

        searchView.setOnSearchClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                searchView.requestFocus();
            }
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM