Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Custom Android Keyboard

Is it possible to edit the default keyboard of an android device? I don't necessarily want to create a new custom keyboard (input method editor) that the user will select as their default editor. Although that is an option. Is it possible to, for example, add an if statement to the keyboard button, "a", and have it display the letter "a", but also have it display the letter, "b" (just an example). Is it possible to do this without creating a custom keyboard, but editing the default devices soft keyboard instead? If not, is is possible to add a custom button to the default android keyboard?

If all of that is not possible, can you send me a link to a website that teaches how to create a simple soft keyboard that can be installed on an android device as the default device keyboard and is not reliant on any app? The android documentation for input method editor is a bit unorganized, but if there is no better tutorial out there than let me know.

Thank you for your time.

2 Answers

I didn't think this was possible but, it may actually be.

Take a look at this on the Developer Reference: http://developer.android.com/reference/android/inputmethodservice/Keyboard.Key.html

Under "Public Constructors", you should see the public Keyboard.Key() constructor.

This should allow you to create your own key on the keyboard and then, you can use the methods listed on the page to also do something if the key is pressed, for example.

It would look something like this:

public void keyboardsetkey (Resources res, Keyboard.Row parent, int x, int y, XmlResourceParser parser) {

}

There isn't much documentation on how this is used here though. There are a few bits and pieces over on the internet about how it can be done but, none are a simple guide on doing this.

What is it you are actually trying to do as, there may be a simpler method such as just displaying a button the user can press and toggling that button between an a or a b, for example?

Thank you for your answer Harry. I want to be able to make conditional statements with the keyboard, when the app is closed and other apps are open. I want to be able to make conditional statements with the default keyboard even when the app isn't being used by the user.

In that case, a custom keyboard is probably the best way to go.

I believe you can actually use the constructors above even when the app is closed (But it must still be running and, to do this, a notification must always be present in the action bar) however, I'm not 100% sure if this also applies for keyboards (Perhaps it would be a security risk so, it gets blocked, I am really not sure).

But, for sure, I would recommend a custom keyboard in your case.

I'd also recommend you just try out some keyboard-related things to see if you can get it right for what you want to use it for.