在 Android 上的应用程序中内置自定义“键盘" [英] Custom 'Keyboard' built in an application on Android

查看:26
本文介绍了在 Android 上的应用程序中内置自定义“键盘"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找为我的应用程序创建自定义键盘.起初,我开始查看 SDK 示例的 SoftKeyboard,但阅读 Android 开发人员组后,我看到了这篇文章:

<块引用>

这个输入法真的不行方法框架应该可以工作.IME 应该是通用输入设施,不是针对特定的应用.如果你需要一些特定于应用程序的输入,您应该构建它进入你的 UI 而不是推送输出到通用 IME.

如何在 UI 中构建特定于应用的输入?我的意思是,有没有办法扩展 Keyboard 应用程序或其他东西并仅在我的应用程序中使用它?

键盘所需的功能:

  • Shift 键显示其他键
  • 平方根或 PI 等特殊键
  • 等等

PS:例如,一个丑陋的解决方案可能是制作一个 ImageButton 表格,但我想制作一些干净的东西.

解决方案

我不确定是否有直接的解决方案(在某种程度上,甚至可以理解原始问题背后的真正原因).

正如原始问题中引用的那样:

<块引用>

如果您需要一些特定于应用的输入,则应将其构建到您的 UI 中而不是将其推送到通用 IME.

这是什么意思,您应该在您的应用程序中尝试通过扩展或修改手机上的软键盘来构建此类输入功能.so 有很多不同的软键盘(基本上,软键盘只是另一个应用程序),因为大多数手机制造商都会创建自己的版本,并且人们会下载 3rd 方键盘(例如 Swype 或 SwiftKey 等).),而且我无法想象有一种方法可以让您破解"这些按钮以添加一些按钮或您想要的任何东西(这也可能是一个主要的安全漏洞,这可能是不可能的另一个原因).

上面引用的建议是,除了键盘之外,您还必须创建一些其他形式的输入.一个这样的例子,如果我可以添加一个非常好的例子,那就是 .每个按钮都处理 onClick 事件,这意味着执行某种操作(更改其他按钮上的标签、显示菜单、在上部标签中显示一些文本或其他),这可能就是它的意义所在.当然,手机的软键盘永远不会显示(因为您不需要带有所有这些按钮的键盘(而且也没有任何输入字段可以输入任何内容).

这一切都归结为已经提到的报价:如果您需要一些特定于应用程序的输入,您应该将其构建到您的 UI 中.或者换句话说:创建按钮(如果你不需要它,不要显示软键盘)并在你点击它们时让事情发生.

<小时>

顺便提一下:如果您确实想要创建自己的输入法(我坚信不是这里的情况),您应该看看在以下资源:

I've been looking to create a custom keyboard for my application. At first, I started to look at the SoftKeyboard for the SDK examples, but reading the Android Developer Group led me to this post:

This is really not how the input method framework is supposed to work. An IME should be a generic input facility, not for a particular application. If you need some app-specific input, you should build it into your UI rather than pushing it out to a generic IME.

How do I build an app-specific input within the UI? I mean, is there a way to extend the Keyboard app or something and use it only in my application?

Features needed for the keyboard:

  • Shift key to display some other keys
  • Special keys like square root or PI
  • etc.

PS: an ugly solution could be to make a table of ImageButton for example, but I wanted to make something clean.

解决方案

I'm not really sure if there's a straight-forward solution to this (to that extent that it is even possible to understand the real reason behind the original question).

As is quoted in the original question:

If you need some app-specific input, you should build it into your UI rather than pushing it out to a generic IME.

What is meant by that, is not that you within your app should try to build in such input features by extending or modifying the soft keyboard on the phone. There are so many different soft keyboards (and basically, the soft keyboard is just another app), since most phone manufacturers create their own version, and people download 3rd party keyboards (such as Swype or SwiftKey etc.), and I can't picture there being a way for you to "hack" into those to add a few buttons or whatever it is you want (which could also be a major security hole, another reason why it probably isn't possible).

What instead the above quote suggests, is that you have to create some other form of input besides the keyboard. One such example, and a very good one if I might add, is how the RealCalc Scientific Calculator looks:

Now this isn't open source, so I can only guess how the code looks like (but it shouldn't be too hard a guess either): in its simplest form, this is just a grid with lots of buttons. Each button handles the onClick event, which would mean performing some kind of action (changing the label on some other buttons, showing a menu, displaying some text in the upper label or whatever), and that's probably pretty much what's to it. And of course, the phone's soft keyboard is never displayed (since you don't need a keyboard with all those buttons (and also there aren't any input fields to write anything in)).

It all boils down to the already mentioned quote: If you need some app-specific input, you should build it into your UI. Or in other words: create buttons (and don't display the soft keyboard if you don't need it) and make things happen when you click them.


And just to have mentioned it: if you do want to create your own IME (which I strongly believe is not the case here), you should have a look at the following resources:

这篇关于在 Android 上的应用程序中内置自定义“键盘"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆