I am trying to create custom ime/softkeyboard for Android devices. How to change its appearance as in kitkat/lollipop system keyboard
Asked
Active
Viewed 506 times
1 Answers
2
You have to create a custom KeyboardView
and override the onDraw
method.
public class CustomKeyboardView extends KeyboardView {
package com.example.xyz;
-----
-----
-----
@Override
public void onDraw(Canvas canvas) {
List<Keyboard.Key> keys = getKeyboard().getKeys();
for (Keyboard.Key key : keys) {
if (key.icon != null) {
key.icon.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
key.icon.draw(canvas);
} else if (key.label != null) {
String keyLabel = key.label.toString();
if (caps) {
keyLabel = keyLabel.toUpperCase();
}
canvas.drawText(keyLabel, key.x + (key.width / 2),
key.y + (key.height / 2) + Utils.dpToPx(5, mContext), mPaint);
}
}
}
-----
-----
}
Now in your keyboard layout (.xml
) file, you must be using <android.inputmethodservice.KeyboardView />
tag.
Change it to <com.example.xyz.CustomKeyboardView />
.
The layout will look like KitKat/Lollipop. You can make other changes as per your requirement.
Note that onDraw()
is called every time you press a key on keyboard. So, do not add code that will take time to process. It can cause keyboard to lag.

Prasad Pawar
- 1,606
- 1
- 15
- 30