定制“键盘”建在Android上的应用建在、键盘、Android

2023-09-12 09:02:24 作者:心已打烊

我一直在寻找,以创建一个自定义键盘为我的申请。起初,我开始看SoftKeyboard的SDK中的例子,但阅读的Andr​​oid开发集团促使我这个职位:

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:

这是真的不怎样输入   方法框架应该工作。   一个IME应该是一个通用的输入   设施,而不是针对特定   应用。如果你需要一些   应用程序特定的输入,你应该建立   它变成你的用户界面,而不是推   它以一个通用的输入法。

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?

Shift键可以显示一些其他的键 在特殊的按键,例如平方根或PI 等

PS:一个丑陋的解决方案是使的ImageButton的例如表,但我要拍的东西干净

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).

由于是引用原题:

如果你需要一些应用程序特定的输入,您应该建设成为你的用户界面   而不是推了一个通用的输入法。

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

什么是意思,是的没有的您在应用程序内应尽量通过的延长或修改的软键盘在手机上建立在这样的输入功能。还有的这样的许多不同的软键盘(基本上,软键​​盘是另一个应用程序),因为大多数手机制造商建立自己的版本,人们下载第三方键盘(如Swype输入或SwiftKey等。 ),我不能想象有一种存在方式为你砍到这些添加几个按钮或者你想不管它是什么(这也可能是一个重大的安全漏洞,另一个原因恐怕是不可能的)。

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).

什么,而不是上面的报价显示,是你需要创建一些的等的形式输入的除了的键盘。这样的一个例子,如果我想补充一个非常好的一个,就是如何 RealCalc科学计算器的样子:

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:

现在这不是开源的,所以我只能猜测如何code样子(但不应该太难猜测其一):在最简单的形式,这仅仅是一个有许多网格按钮的。每个按钮处理onClick事件,这意味着执行某种动作(改变一些其他按钮的标签,显示一个菜单,显示在上标签或其他一些文本),而这可能是pretty的很多东西是它。当然,手机的软键盘,从不显示(因为你并不需要所有的这些按钮的键盘(也没有任何输入栏写的任何东西))。

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:

屏幕上的输入法 创建输入法 软键盘样本 Onscreen Input Methods Creating an Input Method Soft Keyboard sample