硬键盘无法聚焦editText

发布于 2024-11-07 11:17:20 字数 306 浏览 1 评论 0原文

我有一个通用的 EditText。这很奇怪,因为我使用硬键盘时无法聚焦。上下文条件:

  1. 切换 Droid 硬键盘,
  2. 启动 Activity,
  3. 点击 editText 输入
  4. ,输入失败。当您按任意键时,editText 就会失去焦点。

为了获得焦点: 按 Dpad,您将看到焦点从屏幕中的第一个小部件开始。最后关注目标EditText。然后就可以输入了。没有这个,你根本无法用硬键盘输入。

软键盘不存在这样的焦点问题。

我使用的是安卓2.2。这是系统错误吗?

I have a common EditText. It's very strange because I can't focus it when use hard keyboard. Context condition:

  1. switch Droid's hardkeyboard on
  2. start the activity
  3. click the editText to input
  4. Fail to input. When you press any key, the editText lost focus.

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.

I am using android 2.2. Is this a system bug?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薯片软お妹 2024-11-14 11:17:20

如上所述,这显然是硬键盘的一个错误。如果您的布局中有 EditText 和 TabHost,则在按下第一个按键时,EditText 会失去焦点,并且按键会被发送到活动。这是解决此问题的方法。在您的活动中实施这一点。

@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 方法中使用它。

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);
}

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.

吃不饱 2024-11-14 11:17:20

我有同样的问题。我有点同意杰伊的观点。通常,TabHost 和/或 TabActivity 使用 LocalActivityManager 来跟踪嵌入的 Activity 或在 FrameLayout 元素中显示的适当 ContentStrategy 组件。简单来说,这是一个典型的嵌入式Activities/嵌入式Views布局问题。编辑文本位于占用触摸屏空间的最顶层活动/视图上,而实际上托管此活动/视图的核心活动可能正在抓住 InputMethodService 焦点并使其远离编辑文本,仅适用于硬键盘场景。软键盘工作得很好。

我对编辑文本所做的一项更改是将输入类型更改为纯十进制。因此,当“编辑文本”获得焦点时,软键盘会显示数字键盘,而不是字母 qwerty 键盘。我在 Motorla Droid Pro 模拟器上运行它,并在 Motodev 网站的 Eclipse 插件中更新了该模拟器。显然,当我在给予编辑文本焦点后尝试从硬键盘输入文本时(并且软键盘显示数字键盘),在单击“ALT + 2”后,软键盘将重新加载作为字母键盘,而编辑文本完全失去焦点。

对我来说,Froyo 版本中的一个严重错误是,对硬键盘设备的支持不足,无法在嵌入其他布局(TabHost 的 FrameLayout)的布局(LinearLayout)中编辑文本视图。

I have the same problem. I kinda agree with Jay. Typically TabHost, and/or TabActivity utilize a LocalActivityManager that keeps track of embedded Activities or appropriate ContentStrategy component that is displayed within the FrameLayout element. In simple words, this is a typical embedded Activities/ embedded Views layout problem. The Edit Text is on the top-most Activity/View that is taking the touch-screen space, while there's a core Activity that is actually hosting this Activity/View that probably is grabbing the InputMethodService focus and keeping it away from the Edit Text, only for the hard-keyboard scenario. The soft-keyboard just works fine.

One change I did to my Edit Text is to change the InputType as purely decimal. So when the Edit Text gains focus, the soft keyboard shows a numeric key-pad and not the alphabetical qwerty key-pad. I ran it on a Motorla Droid Pro emulator, that I updated in Eclipse Plugins from the Motodev website. Apparently, when I try to enter text from the hard keyboard after having given focus for the Edit Text (and the soft-keyboard is showing a numeric key-pad), after I click 'ALT + 2', the soft-keyboard is reloaded as alphabetic key-pad while the Edit Text loses focus entirely.

Seems like a serious bug to me in the Froyo release, insufficient support for hard-keyboard devices for edit text views in layouts (LinearLayout) that are embedded in other layouts (FrameLayout of a TabHost).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文