How Does An Android App Load A Keyboard?
Solution 1:
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.
Anyhow:
- 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);
.
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.
Solution 2:
Keyboard
and KeyboardView
are for making alternative input method engines (IME). These are then able to be chosen by the user, just as they can install Swype, Graffiti, and other ones from the Android Market.
You, as a developer, can create such an IME, but you cannot force it upon the user.
Solution 3:
using the inputType attribute in your editText view will help pick between the different system keyboards (phone, email, etc) Also the APIDemos application that comes with the SDK has an example of how to implement a forced custom keyboard for your app only.
Post a Comment for "How Does An Android App Load A Keyboard?"