Michael Kent
Michael Kent

Reputation: 383

android default keyboard layout styling

I am wanting to alter the default (whatever is on your device's) keyboard, so that the colors displayed reflect my apps overarching theme better. for example white background, light blue keys, that go dark blue when pressed.

Using this tutorial I have created a custom Keyboard and am able to change the keybackground.xml to adjust the colors of keys on a KeyboardView etc.

<android.inputmethodservice.KeyboardView
    android:id="@+id/keyboardview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:focusable="true"
    android:focusableInTouchMode="true" 
    android:visibility="gone"
android:keyBackground="@drawable/keybackground"/>

what I am looking for is to apply this style to the default keyboard used by the device, failing that i have also looked for a copy of the keyboard layout xml so i can create a fully custom one with default key layout.

one possible method i have contemplated is replacing the following line (explained in the tutorial link).

mKeyboardView.setKeyboard(new Keyboard(mHostActivity, layoutid));

with another method of instantiating/getting default Keyboard.

Edit

I only require this keyboard to be displayed within my application.

Upvotes: 5

Views: 4014

Answers (3)

HarshMarshmallow
HarshMarshmallow

Reputation: 1037

If you just want to add the keyboard to your application, add the keyboardview to your layout with visibility:gone. When the user clicks on an edittext field, consume the event going to the default keyboard and show your keyboard instead. Keep track of the keys pressed and append them wherever you need. Don't forget to hide your keyboard when the user clicks off the edittext field.

Upvotes: 0

FreewheelNat
FreewheelNat

Reputation: 2947

You cannot change the colors of any of the installed keyboards (default or not), though some may allow you to create themes for them as a kind of extension but it would be something the user would install separately from your app. Keyboard apps are separate apps from yours and Android doesn't give you direct access to their layouts. You can create your own keyboard app of course, but this wouldn't make sense to do this in your case (as you're only after customizing colors for matching your app).

Additionally, it would be bad UX if each app changed the keyboard colors. Presumably, the user has picked a keyboard and theme that suits his/her visual needs, so it would be annoying if it changed between apps (imagine if you are a color blind user and an app changes the keyboard to colors you can't distinguish so you couldn't see what is on the keys anymore!).

Upvotes: 3

Arveen
Arveen

Reputation: 868

You cannot do what you are planning to do in android, as it would be a massive security hole. Your app cannot change the default keyboard. What you can do is, make a new custom keyboard style and add it as a choice for the user. The user will have to go to settings->keyboard and select your keyboard. You will have to implement InputMethodService. Be warned though, its not a easy task. A lot of effort goes into it.

Upvotes: 0

Related Questions