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


- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 拆分 Drawable 2022-01-01