Android的文本字段:设定对焦+软输入编程 [英] Android TextField : set focus + soft input programmatically

查看:87
本文介绍了Android的文本字段:设定对焦+软输入编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,我有一个搜索的EditText,我想以编程方式触发click事件的行为的领域,即文本字段提供焦点,并在必要(如果没有硬键盘可用)显示软键盘。

In my view, I have a search EditText and I would like to trigger programmatically the behaviour of a click event on the field, i.e give focus to the text field AND display soft keyboard if necessary (if no hard keyboard available).

我试过 field.requestFocus()。本场实际上获得焦点,但不显示软键盘。

I tried field.requestFocus(). The field actually gets focus but soft keyboard is not displayed.

我试过 field.performClick()。但是,这仅调用字段的OnClickListener

I tried field.performClick(). But that only calls the OnClickListener of the field.

你知道吗?

推荐答案

好先生,试试这个:

edittext.setFocusableInTouchMode(true);
edittext.requestFocus();

林不知道,但是这可能需要在某些手机上(一些较旧的设备):

Im not sure, but this might be required on some phones (some of the older devices):

final InputMethodManager inputMethodManager = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(edittext, InputMethodManager.SHOW_IMPLICIT);

这篇关于Android的文本字段:设定对焦+软输入编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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