19

Is there a way to create an app specific soft keyboard on Android? After reading about InputMethodService docs and checking out alternative keyboard apps out there, I figure the alternate keyboard can only be configured for system wide usage (through Settings -> Locale and Text).

If the answer to above question is no, then is there at least a way to load a custom dictionary and override the default dictionary of the system keyboard (only when my app is in use)? That will help in giving very relevant suggestions to the user when he has only tapped couple of keys.

Chathuranga Chandrasekara
  • 20,548
  • 30
  • 97
  • 138
Jayesh
  • 51,787
  • 22
  • 76
  • 99

2 Answers2

21

If you just want a View that looks and acts like a soft keyboard, I did that in my SmallKeyboard class. You just need to extend android.inputmethodservice.KeyboardView and decide on layout. See the onKey and onText methods at the end of that file for the action taken when keys are pressed.

Instead of my keyboard model inner class, you could load it from XML if your key set is fairly constant.

Chris Boyle
  • 11,423
  • 7
  • 48
  • 63
  • That looks useful. I installed SGTPuzzles to see how the keyboard works, but I couldn't get it on screen. I only get the redo/undo buttons. Which puzzle will popup the instance of SmallKeyboard? Thanks. – Jayesh Jan 27 '10 at 15:39
  • The undo/redo buttons are actually such an instance, but more interesting instances can be seen in puzzles where number entry is required: Filling, Solo, Unequal (and coming soon, Keen and Towers). Also Guess and Map have minimal extra buttons. – Chris Boyle Jan 27 '10 at 21:38
  • 5
    The question wasn't answered in full. How do you tell your application to use this custom keyboard? – Lukasz Wiklendt Dec 08 '10 at 08:04
  • 3
    You don't tell it to use this keyboard. It's a view, so you treat it as any other normal view. – Valentin Rocher Dec 08 '10 at 08:14
  • `my SmallKeyboard class` link is now 404. – Graeme Oct 11 '11 at 08:40
  • Its 404 again. And I didnt quite get the answer to the question, how to get this keyboard to popup instead of the system keyboard? I get that its just view like any other view. But when the focus is put on an edit text, how to get this keyboard to popup instead of the system keyboard? – Greg Ennis Feb 10 '15 at 15:01
  • @GregEnnis Link fixed. As for disabling the built-in keyboard on an EditText, it looks like you could try https://developer.android.com/reference/android/widget/TextView.html#setInputType(int) with TYPE_NULL but I haven't tested that. – Chris Boyle Feb 10 '15 at 17:35
9

The Android Nethack application has a complete and clear source code example of how to create a custom keyboard for an application, how to display it on screen and how to define multiple keyboard layouts. It contains pretty much everything you need to know.

It is by far the best example I have seen.

http://code.google.com/p/nethack-android/

Torben
  • 3,805
  • 26
  • 31