Custom 'Keyboard' Built in an Application on Android

Custom 'Keyboard' built in an application on Android

I'm not really sure if there's a straight-forward solution to this (to that extent that it is even possible to understand the real reason behind the original question).

As is quoted in the original question:

If you need some app-specific input, you should build it into your UI
rather than pushing it out to a generic IME.

What is meant by that, is not that you within your app should try to build in such input features by extending or modifying the soft keyboard on the phone. There are so many different soft keyboards (and basically, the soft keyboard is just another app), since most phone manufacturers create their own version, and people download 3rd party keyboards (such as Swype or SwiftKey etc.), and I can't picture there being a way for you to "hack" into those to add a few buttons or whatever it is you want (which could also be a major security hole, another reason why it probably isn't possible).

What instead the above quote suggests, is that you have to create some other form of input besides the keyboard. One such example, and a very good one if I might add, is how the RealCalc Scientific Calculator looks:

RealCalc Scientific Calculator

Now this isn't open source, so I can only guess how the code looks like (but it shouldn't be too hard a guess either): in its simplest form, this is just a grid with lots of buttons. Each button handles the onClick event, which would mean performing some kind of action (changing the label on some other buttons, showing a menu, displaying some text in the upper label or whatever), and that's probably pretty much what's to it. And of course, the phone's soft keyboard is never displayed (since you don't need a keyboard with all those buttons (and also there aren't any input fields to write anything in)).

It all boils down to the already mentioned quote: If you need some app-specific input, you should build it into your UI. Or in other words: create buttons (and don't display the soft keyboard if you don't need it) and make things happen when you click them.


And just to have mentioned it: if you do want to create your own IME (which I strongly believe is not the case here), you should have a look at the following resources:

  • Onscreen Input Methods
  • Creating an Input Method
  • Soft Keyboard sample

Want custom keyboard to ONLY be used for MY APP and restore previous when app loses focus

I just want MY app to change the keyboard for ITSELF

That is not possible through the input method editor system. The user, not you, is in charge of the input method that the user uses.

Rather than do that, I may as well just add buttons to perform the keypresses I hoped to invoke via a custom keyboard.

That is your only option.

Android: Create system-wide custom keyboards, like iOS8 extension keyboard?

Is there a way to accomplish this task?

Yes. It has been possible for several years on Android to create custom input method editors.

Custom keyboard for Android app

But I don't know how to set this Method to my EditText and disable standard keyboard

You can't. The user chooses the input method, because the input method is system-wide.

May I solve this with custom Input Method or should I create keyboard as custom view instead?

Unless you are going to take the time to support all users — the visually impaired, those using a physical keyboard, etc. — you should not do this at all.

Assuming that you are going to handle all users, it would need to be a custom view if you are going to force the user to use it.

Creating custom keyboard for android

To customize the keyboard you will need to modify your "qwerty" in the xml folder and the keyboard on the layout folder. I'll show some examples:

This goes on the layout folder

<?xml version="1.0" encoding="UTF-8"?>
<com.example.keyboard.MyKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:keyPreviewLayout="@layout/preview"
android:keyBackground="@drawable/key_selector"
android:shadowRadius="0.0"
android:keyTextColor="#000000"
/>

And this goes on the xml folder:

<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="10%p"
android:keyHeight="8%p">

<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyWidth="9.6%p">
<Key android:codes="113" android:keyLabel="q" />
<Key android:codes="119" android:keyLabel="w" />
<Key android:codes="101" android:keyLabel="e" />
<Key android:codes="114" android:keyLabel="r" />
<Key android:codes="116" android:keyLabel="t" />
<Key android:codes="121" android:keyLabel="y" />
<Key android:codes="117" android:keyLabel="u" />
<Key android:codes="105" android:keyLabel="i" />
<Key android:codes="111" android:keyLabel="o" />
<Key android:codes="112" android:keyLabel="p" />
</Row>
<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyWidth="9.6%p">
<Key android:codes="97" android:keyLabel="a" android:keyEdgeFlags="left" android:horizontalGap="5%p" />
<Key android:codes="115" android:keyLabel="s" />
<Key android:codes="100" android:keyLabel="d" />
<Key android:codes="102" android:keyLabel="f" />
<Key android:codes="103" android:keyLabel="g" />
<Key android:codes="104" android:keyLabel="h" />
<Key android:codes="106" android:keyLabel="j" />
<Key android:codes="107" android:keyLabel="k" />
<Key android:codes="108" android:keyLabel="l" />
</Row>
<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyWidth="9.6%p">
<Key android:codes="3" android:keyIcon="@drawable/keyboard_shift_off_normal"
android:keyWidth="13.7%p"/>
<Key android:codes="122" android:keyLabel="z" android:horizontalGap="1%p"/>
<Key android:codes="120" android:keyLabel="x" />
<Key android:codes="99" android:keyLabel="c" />
<Key android:codes="118" android:keyLabel="v" />
<Key android:codes="98" android:keyLabel="b" />
<Key android:codes="110" android:keyLabel="n" />
<Key android:codes="109" android:keyLabel="m" />
<Key android:codes="-5" android:keyIcon="@drawable/sym_keyboard_delete_dim"
android:keyWidth="13.7%p"
android:horizontalGap="1%p"/>
</Row>
<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyWidth="9.6%p">
<Key android:codes="-16" android:keyIcon="@drawable/keyboard_symbol"
android:keyWidth="18.7%p"/>
<Key android:codes="44" android:keyLabel="," android:horizontalGap="1%p"/>
<Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_feedback_space" android:keyWidth="40%p"/>
<Key android:codes="46" android:keyLabel="."/>
<Key android:codes="-3" android:keyIcon="@drawable/keyboard_go"
android:keyWidth="18.5%p" android:horizontalGap="1%p"/>
</Row>
</Keyboard>

Like you said, you can extend a class from keyboard layout, but it's more for customize keyboard events, like onTouch, onLongKeyPress,



Related Topics



Leave a reply



Submit