How does an Android app load a keyboard?

I need to pick up several different keyboards: the "standard" keyboard with the Ctrl and Alt keys; perhaps the cursor bar; etc.

I found a class Keyboardthat would allow me to define a keyboard in an XML resource. I found that the class KeyboardViewhas a method setKeyboard... and so far I have not found another class that accepts an instance Keyboard.

How can i use KeyboardView? I tried adding it to my XML activity file; find it at runtime with findViewById; and then calling setKeyboard... but all this was ruined by my layout, and not to display a special keyboard.

+3
source share
3 answers

This turns out to be very doable, and my initial problems were probably more related to the general novelty of Android (this is my first Android application), and not to KeyboardView. In particular, I'm used to the fact that visibility is a simple binary property.

Anyway:

  • Declare KeyboardViewin your xml file with android:visibility="gone".
  • Before making the view visible, call setKeyboard()to attach the keyboard. This is important because it KeyboardViewgets its size from the keyboard.
  • To get raw key events, call KeyboardView.setOnKeyboardActionListener(). After reorganizing this function from Dialogback to my core View, I put the functionality OnKeyboardActionListenerin a standalone class, but this is not necessary.
  • keyboardView.setEnabled(true);. , (), ; , setEnabled(false).
  • keyboardView.setPreviewEnabled(true); - , biox .
  • , , keyboardView.setVisibility(VISIBLE);.

, , keyboardView.setVisibility(GONE);. ( " ", setKeyboard . Map<<Integer, Keyboard> ; , , .

+3

Keyboard KeyboardView (IME). , Swype, Graffiti Android Market.

, , IME, .

0

inputType editText (, ..). APIDemos , SDK, , .

0

Source: https://habr.com/ru/post/1769657/


All Articles