Hard keyboard Fail to focus editText(硬键盘无法聚焦editText)
问题描述
我有一个通用的 EditText.这很奇怪,因为我在使用硬键盘时无法对焦.上下文条件:
I have a common EditText. It's very strange because I can't focus it when use hard keyboard. Context condition:
- 打开 Droid 的硬键盘
- 开始活动
- 点击editText输入
- 输入失败.当您按任意键时,editText 会失去焦点.
要获得焦点:按 Dpad,您将看到焦点从屏幕中的第一个小部件开始.最后关注目标EditText.然后就可以输入了.没有这个,你根本无法用硬键盘输入.
To get focus: press Dpad and you will see the focus starts from the 1st widget in the screen. And finally focus on the target EditText. Then you can input. Without this, you can't input with hard keyboard at all.
软键盘没有这样的焦点问题.
Soft keyboard doesn't have such focus problem.
我使用的是安卓 2.2.这是系统错误吗?
I am using android 2.2. Is this a system bug?
推荐答案
如上所述,这显然是硬键盘的错误.如果您的布局中有一个 EditText 和一个 TabHost,则在按下第一个键时,EditText 失去焦点并且按键被发送到活动.这是解决此问题的方法.在您的活动中实现这一点.
As mentioned above this is clearly a bug with hard keyboard. If you have an EditText and a TabHost in your layout, on first key pressed, EditText lose focus and key press is sent to the activity instead. Here is a work around to this problem. Implement this in your activity.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
final EditText myInputField = (EditText) findViewById(R.id.MyInputEditText);
// this will happen on first key pressed on hard-keyboard only. Once myInputField
// gets the focus again, it will automatically receive further key presses.
if (!myInputField.hasFocus()){
myInputField.requestFocus();
myInputField.onKeyDown(keyCode, event);
}
return super.onKeyDown(keyCode, event);
}
如果您有多个 EditText 字段,则需要在类变量中跟踪当前聚焦的 EditText 并在 onKeyDown 方法中使用它.
if you have multiple EditText fields, you will need to keep track of currently focused EditText in a class variable and use it in onKeyDown method.
这篇关于硬键盘无法聚焦editText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:硬键盘无法聚焦editText
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01