且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何Android应用程序加载的键盘?

更新时间:2023-02-06 22:35:33

这原来是非常可行的,和我最初的问题,可能有更多的是与一般的Andr​​oid 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.

总之:


  1. 声明 KeyboardView 与XML文件的android:知名度=水涨船高

  2. 您使视图可见之前,调用 setKeyboard()附加键盘。这一点很重要,因为 KeyboardView 从键盘获取其大小。

  3. 要获取原始的关键事件,请拨打 KeyboardView.setOnKeyboardActionListener()。从对话框回到我的主查看,我把 OnKeyboardActionListener 在一个独立的类的功能,但是,这是没有必要的。

  4. 我称之为 keyboardView.setEnabled(真); 。这似乎并不为必要,但我不知道(但)在什么情况下会的问题;的也许的只有当你调用的setEnabled(假)

  5. 我称之为 keyboardView.set previewEnabled(真); - 这是非常有用的,如果用户不会从一个输入BIOX正上方获得视觉反馈键盘。

  6. 然后,用键盘的所有设置,调用 keyboardView.setVisibility(可见);

  1. Declare the KeyboardView in your XML file with android:visibility="gone".
  2. Before you make the view visible, call setKeyboard() to attach a keyboard. This is important, as the KeyboardView gets its size from the keyboard.
  3. To get raw key events, call KeyboardView.setOnKeyboardActionListener(). After refactoring this functionality from a Dialog back to my main View, I put the OnKeyboardActionListener functionality in a stand-alone class, but this is not necessary.
  4. 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 call setEnabled(false).
  5. 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.
  6. Then, with the keyboard all set, call keyboardView.setVisibility(VISIBLE);.

要隐藏键盘在适当的时候,只需拨打 keyboardView.setVisibility(GONE); 。要改变键盘(如在一个shift键,或周期通过的非符号键盘按键,只需拨打 setKeyboard 一次。我用地图<<整数,键盘> 来实现一个懒惰的创建模式;弱引用可能是可取的,如果该程序会长时间运行,键盘不会有太大使用

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.