如何Android应用程序加载的键盘? [英] How does an Android app load a keyboard?
问题描述
我需要带了几个不同的键盘:标准键盘Ctrl和Alt键;也许光标垫;等
I need to bring up a few different keyboards: a 'standard' keyboard with Ctrl and Alt keys; maybe a cursor pad; and so on.
我已经找到了键盘
类,这将让我在一个XML资源定义的键盘。我发现,在 KeyboardView
类有一个 setKeyboard
方法......,到目前为止,我还没有发现任何其他类需要一个键盘
实例。
I have found the Keyboard
class, which would let me define a keyboard in an XML resource. I have found that the KeyboardView
class has a setKeyboard
method ... and, so far, I have not found any other class that takes a Keyboard
instance.
我应该如何使用 KeyboardView
?我想添加一个到我的活动的XML;在运行时用 findViewById
找到它;然后调用 setKeyboard
...但是这一切都做的是弄乱我的布局和不可以调出专用键盘。
How am I supposed to use the KeyboardView
? I tried adding one to my activity's XML; finding it at runtime with findViewById
; and then calling setKeyboard
... but all this did was mess up my layout and not bring up the special keyboard.
推荐答案
这原来是非常可行的,和我最初的问题,可能有更多的是与一般的Android newbiness(这是我的第一个Android应用程序),而不是KeyboardView 。特别是,我已经习惯了知名度是一个简单的二元属性。
This turns out to be very doable, and my initial problems probably had more to do with general Android newbiness (this is my first Android app) and not the KeyboardView. In particular, I'm used to visibility being a simple binary property.
总之:
- 声明
KeyboardView
与XML文件的android:知名度=水涨船高
- 您使视图可见之前,调用
setKeyboard()
附加键盘。这一点很重要,因为KeyboardView
从键盘获取其大小。 - 要获取原始的关键事件,请拨打
KeyboardView.setOnKeyboardActionListener()
。从对话框
回到我的主查看
,我把OnKeyboardActionListener <重构这一功能后, / code>在一个独立的类的功能,但是,这是没有必要的。
- 我称之为
keyboardView.setEnabled(真);
。这似乎并不为必要,但我不知道(但)在什么情况下会的问题;的也许的只有当你调用的setEnabled(假)
。 - 我称之为
keyboardView.set previewEnabled(真);
- 这是非常有用的,如果用户不会从一个输入BIOX正上方获得视觉反馈键盘。 - 然后,用键盘的所有设置,调用
keyboardView.setVisibility(可见);
- Declare the
KeyboardView
in your XML file withandroid:visibility="gone"
. - Before you make the view visible, call
setKeyboard()
to attach a keyboard. This is important, as theKeyboardView
gets its size from the keyboard. - To get raw key events, call
KeyboardView.setOnKeyboardActionListener()
. After refactoring this functionality from aDialog
back to my mainView
, I put theOnKeyboardActionListener
functionality in a stand-alone class, but this is not necessary. - I call
keyboardView.setEnabled(true);
. This does not seem to be necessary, but I am not sure (yet) under what circumstances it would matter; perhaps only if you callsetEnabled(false)
. - I call
keyboardView.setPreviewEnabled(true);
- this is especially useful if the user won't be getting visual feedback from an input biox right above the keyboard. - Then, with the keyboard all set, call
keyboardView.setVisibility(VISIBLE);
.
要隐藏键盘在适当的时候,只需拨打 keyboardView.setVisibility(GONE);
。要改变键盘(如在一个shift键,或周期通过的非符号键盘按键,只需拨打 setKeyboard
一次。我用地图&LT;&LT;整数,键盘&GT;
来实现一个懒惰的创建模式;弱引用可能是可取的,如果该程序会长时间运行,键盘不会有太大使用
To hide the keyboard when appropriate, just call keyboardView.setVisibility(GONE);
. To change the keyboard (as on a shift key, or a cycle-through-the-symbol-keyboards key, just call setKeyboard
again. I use a Map<<Integer, Keyboard>
to implement a lazy-create pattern; a weak reference may be desirable, if the program will run for a long time and the keyboard will not be used much.
这篇关于如何Android应用程序加载的键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!