Android 安卓应用专用软键盘
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1896939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android app specific soft keyboard
提问by Jayesh
Is there a way to create an app specific soft keyboard on Android? After reading about InputMethodService docs and checking out alternative keyboard apps out there, I figure the alternate keyboard can only be configured for system wide usage (through Settings -> Locale and Text).
有没有办法在 Android 上创建特定于应用程序的软键盘?在阅读了 InputMethodService 文档并查看了替代键盘应用程序之后,我认为替代键盘只能配置为系统范围的使用(通过设置 -> 区域设置和文本)。
If the answer to above question is no, then is there at least a way to load a custom dictionary and override the default dictionary of the system keyboard (only when my app is in use)? That will help in giving very relevant suggestions to the user when he has only tapped couple of keys.
如果上述问题的答案是否定的,那么至少有一种方法可以加载自定义字典并覆盖系统键盘的默认字典(仅当我的应用程序正在使用时)?当用户只点击几个键时,这将有助于向用户提供非常相关的建议。
回答by Chris Boyle
If you just want a View that looks and acts like a soft keyboard, I did that in my SmallKeyboard class. You just need to extend android.inputmethodservice.KeyboardViewand decide on layout. See the onKey and onText methods at the end of that file for the action taken when keys are pressed.
如果你只想要一个看起来和行为都像软键盘的视图,我在我的 SmallKeyboard 类中做到了。您只需要扩展android.inputmethodservice.KeyboardView并决定布局。请参阅该文件末尾的 onKey 和 onText 方法,了解按下键时所采取的操作。
Instead of my keyboard model inner class, you could load it from XMLif your key set is fairly constant.
如果您的键集相当恒定,您可以从 XML 加载它,而不是我的键盘模型内部类。
回答by Torben
The Android Nethack application has a complete and clear source code example of how to create a custom keyboard for an application, how to display it on screen and how to define multiple keyboard layouts. It contains pretty much everything you need to know.
Android Nethack 应用程序有一个完整清晰的源代码示例,说明如何为应用程序创建自定义键盘、如何在屏幕上显示以及如何定义多个键盘布局。它几乎包含了您需要了解的所有内容。
It is by far the best example I have seen.
这是迄今为止我见过的最好的例子。