21

I'd like to write an custom keyboard which should work on all devices that are running Android 4.0 and up. So first I searched the net but didn't found anything about that. So how can I create an app which replaces the stock keyboard of Android?

What I'd like to know:

  1. Is there a good tutorial out there? Do you guys have sample code?
  2. Do I need root to do this?
  3. What's the structure behind it? (Is it just a regular Activity with a Service??)
  4. Is it possible to read out the Inputbox within the keyboard?
1

3 Answers 3

20

So, I did this for about 2 years, when I worked on Swype. You don't need root, you just need to implement an InputMethodService. You can get the text out of most textboxes, but not all (not all edit fields correctly implement their half of the APIs. Particularly anything with an input type INPUT_TYPE_NULL will not work well). To get the text you would call inputConnection.getExtractedText

Be warned- the API is bad, and apps are hit and miss on working with it. A basic keyboard is easy, but try and do anything complex and you'll spend a lot of time. A lot of man hours went in to the big keyboards

Sign up to request clarification or add additional context in comments.

4 Comments

allright, so its getting very hard when i'd like to have in my keyboard some kind of spinnerbox or something, which let the user change the text? Am I right in this? Or can i just overlay a new layout in there?
SO the idea behind that part of the framework is that you'd be implementing the entire keyboard- tapping, prediction, etc. This includes drawing. So adding a spinner shouldn't be a problem, despite the fact you're a service the IME is allowed to put up a UI (the only such service). So just put the spinner in your layout. If you just want a standard keyboard with no prediction in there there's a lot of help in Android, but I'm not sure how much- we did everything custom, our layout was just a custom view and we drew it ourselves.
allright, so I'll give this a shot, btw. do you know about any other example code except the SoftKey which is from Google?
There's probably a small tutorial or two, but not much. If you go into the AOSP code you can probably find android's keyboard. It used to be called "latinime". That's your best example, and you may be able to alter it to your liking.
9

So first I searched the net but didn't found anything about that

Creating an input method is covered in the Android developer documentation, which is on the Internet.

Do you guys have samplecode?

There is a sample in the samples/ directory of your SDK installation, if you downloaded sample code from the SDK Manager. Look for SoftKeyboard.

Do I need root to do this?

No.

What's the structure behind it? (Is it just a regular Activity with a Service??)

It is an InputMethodService.

9 Comments

hmm didn't found it in the developer documentation, btw @CommonsWare is this topic covered in one of your books?
@safari: No, sorry. It's on the list, but it's not a high priority, because it is a rather specialized topic.
allright =), to the last question, is it possible that I can read out what I wrote into the inputbox (edittext whatever), and replace it?
@safari: I am not familiar with how the InputMethodService works with respect to editing existing text, sorry.
@CommonsWare: thanks for the answer. I have used the SoftKeyboard(given in the android sdk sample). But the auto-suggest bar is not showing in the keyboard. How can I show the auto-suggest words in that SoftKeyboard.
|
2
  1. Is there a good tutorial out there? Do you guys have sample code?

Hereby a good tutorial:
http://code.tutsplus.com/tutorials/create-a-custom-keyboard-on-android--cms-22615

  1. Do I need root to do this?

No, root is not required to do this.

  1. What's the structure behind it? (Is it just a regular Activity with a Service??)

You need to use the inputMethodService, see the documentation.

  1. Is it possible to read out the Inputbox within the keyboard?

root: no

Is it possible to read out the Inputbox within the keyboard?

yes it is possible.

InputConnection ic = getCurrentInputConnection(); String currentText = ic.getExtractedText(new ExtractedTextRequest(), 0).text; 

3 Comments

Thanks. What is root: no? Edit your post, please.
@CoolMind his question was do i need to root my device to implement such thing and the answer is no, nothing to edit in there
if you see again at your answer, you will notice, that it is number 2. And you repeated it in number 4 again.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.