在 android 中的输入法编辑器/软键盘上设置显式焦点

发布于 2024-12-05 05:24:21 字数 711 浏览 0 评论 0原文

我正在使用 Android 的标准软键盘输入法编辑器。在按下特定键并且编辑文本视图获得焦点后,我在 Android 模拟器上显示软键盘。我的目的是在软键盘出现在屏幕上后将焦点设置在它上。我知道软键盘通常用于根本没有硬键盘的输入,但就我而言,我正在开发的应用程序需要此功能,因为它将在自定义设备上运行,并且 android 的源代码正在针对自定义功能进行修改。有人知道如何解决这个问题吗?触摸模式是否可能不允许将焦点设置在键盘上?

编辑:澄清

抱歉含糊不清。基本上,在以下情况下,我需要软键盘提供以下功能。

  1. 用户将光标(使用键盘)放在 EditText 上。因为他使用的是键盘,所以应用程序不会显示软键盘。
  2. 用户按下键盘上的特殊键以调出软键盘。
  3. 焦点应从 EditText 更改为 SOFTKEYBOARD,这意味着用户应该能够使用硬键盘在软键盘上导航和选择按键。当然,这意味着按键事件应该添加到标准软键盘中。
  4. 用户选择一个键后,按 Enter 键(例如),并且键字符应出现在编辑文本上。

现在的问题是,当我调出软键盘时,焦点仍然在编辑文本上。我想知道是否可以将焦点放在软键盘上并使用硬键盘在其上移动。正如我之前告诉过你的,这是自定义功能。也许我以错误的方式解决这个问题,一个带有键盘视图的简单弹出窗口就足够了。

劳伦我认为你是对的,因为标准软键盘是作为服务实现的,并且不遵循常规视图的规则。

任何建议表示赞赏。

谢谢

I am working with Android's standard softkeyboard input method editor. I am showing the softkeyboard on my android emulator after a specific key has been pressed and an edittext view has focus. My purpose is to set the focus on the softkeyboard after it appears on screen. I know softkeyboards are generally used for input without a hard keyboard at all, but in my case the app I am developing needs this functionality as it will run on a custom device and android's source is being modified for custom functionality. Does anybody have any idea on how to tackle this problem? Could it be possible that touch mode does not allow to set focus on the keyboard?

EDIT: Clarification

Sorry for being ambiguous. Basically I require the following functionality from the softkeyboard in the following case.

  1. User places cursor (using keyboard) on EditText. Because he is using a keyboard the application will not show the softkeyboard.
  2. User presses a SPECIAL key on the keyboard to bring up the softkeyboard.
  3. Focus should change frrom the EditText to the SOFTKEYBOARD, meaning that the user should be able to navigate and select keys on the softkeyboard using the hard keyboard. Of course this means that key events should be added to the standard softkeyboard.
  4. After user chooses a key he presses enter (for example) and the key character should appear on the edittext.

Right now the problem is that when i bring up the softkeyboard the FOCUS remains on the edittext. I would like to know if it is even possible to place the focus on the softkeyboard and move on it using a hard keyboard. As i told you before this is custom functionality. Maybe I am tackling this problem the wrong way and a simple popup window with a keyboard view would suffice.

Lauren I think you are right in the sense that the standard softkeyboard is implemented as a service and does not follow the rules of regular views.

Any advice is appreciated.

Thanks

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

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

发布评论

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

评论(1

我的鱼塘能养鲲 2024-12-12 05:24:21

我认为这里有两种“焦点”:

  • EditText 焦点是必要的,以确保键盘事件只有一个接收器。
  • 键盘焦点,意味着键盘可见并且可以按下按键。

据我了解,在android中,只有EditText获得焦点。键盘在服务中运行并通过特殊的 Insets< 获取触摸事件/a> 类。

如果您需要的只是强制键盘可见,您应该尝试来自

编辑

我认为有两种方法可以做到这一点,具体取决于您是否希望此键盘特定于某个活动或随处可用。

  • 特定于活动

据我了解,负责显示键盘视图的输入方法服务不允许您实现此目的。

我最好的建议是创建一个具有“可聚焦键”功能的专用键盘视图(扩展键盘视图将是一个很好的起点)。

您可以更改键盘可见性(使用 View.VISIBLE 和 View.GONE)以使其显示和消失。

然后,您应该对自己的行为进行编码,以突出显示具有焦点的键并相应地移动它。

您的 Activity 还必须记住最后一个具有焦点的 EditText,以便向其发送文本或键码。

  • 系统范围

如果您需要此行为在系统上的任何地方都可用,那么您必须提供自己的输入法服务。我建议你看看这篇文章以及 SDK 中的 SoftKeyboard 示例

请注意,您还需要如上所述创建自定义 KeyboardView,但不需要记住 EditText 焦点。

I think that there are two kind of 'focus' here:

  • EditText focus is necessary to ensure there is exactly one receiver for the keyboard events
  • Keyboard focus, meaning the keyboard is visible and the keys can be pressed.

To my understanding, in android, only the EditText gets the focus. The keyboard runs in a service and gets touch events thank to a special Insets class.

If all you need is to force your keyboard visibility, you should try answers from this question.

EDIT

I think there are two ways to do so depending on if you want this keyboard to be specific to an activity or available everywhere.

  • Activity specific

To my understanding, the inputmethodservice that is responsible for showing the keyboardview will not allow you to achieve this.

My best advice is that you create a specialized keyboard view that have this "focusable keys" feature (extending keyboardview would be a good starting point).

You can change the keyboard visibility (using View.VISIBLE and View.GONE) to make it appear and disappear.

Your should then code your own behavior to highlight the key with the focus and move it accordingly.

Your activity will also have to remember the last EditText that had focus to send text or keyCodes to it.

  • System wide

If you need this behavior to be available everywhere on the system, then you must provide your own inputmethodservice. I advice you take a look at this post as well as the SoftKeyboard sample in the SDK.

Please note that you will also need to create a custom KeyboardView as described above, but without the need to remember the EditText focus.

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