Android TextField : set focus + soft input programmatically(Android TextField:以编程方式设置焦点+软输入)
问题描述
在我看来,我有一个搜索 EditText,我想以编程方式触发该字段上单击事件的行为,即,将焦点放在文本字段上,并在必要时显示软键盘(如果没有可用的硬键盘).
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();
我不确定,但某些手机(某些旧设备)可能需要这样做:
I'm 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 TextField:以编程方式设置焦点+软输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android TextField:以编程方式设置焦点+软输入
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
