如何Android应用程序加载的键盘? [英] How does an Android app load a keyboard?

查看:91
本文介绍了如何Android应用程序加载的键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要带了几个不同的键盘:标准键盘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.

推荐答案

这原来是非常可行的,和我最初的问题,可能有更多的是与一般的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 <重构这一功能后, / code>在一个独立的类的功能,但是,这是没有必要的。

  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 一次。我用地图&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屋!

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