3

I am implementing my own custom keyboard.

I use this tutorial for implementing keyboard

<?xml version="1.0" encoding="utf-8"?>

 <Row>
    <Key android:keyLabel="q" android:keyEdgeFlags="left"/>
    <Key android:keyLabel="w"/>
    <Key android:keyLabel="e"/>
    <Key android:keyLabel="r"/>
    <Key android:keyLabel="t"/>
    <Key android:keyLabel="y"/>
    <Key android:keyLabel="u"/>
    <Key android:keyLabel="i"/>
    <Key android:keyLabel="o"/>
    <Key android:keyLabel="p" android:keyEdgeFlags="right"/>
</Row>

I want have 2 label on key button.The same as on image below (red):

enter image description here

How can I change the keyboard xml to have this? When we make the long click on button we should choose numbers instead of letters

Tim
  • 1,606
  • 2
  • 20
  • 32

1 Answers1

6

you need to create a KeyboardView extends class and override OnDraw method like this:

public class MKeyboardView extends KeyboardView {
    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        Paint paint = new Paint();
        paint.setTextSize(15);
        paint.setColor(Color.GRAY);

        List<Key> keys = getKeyboard().getKeys();
        for(Key key: keys) {
        if(key.codes[0] == 113)
            canvas.drawText("1", key.x + (key.width/2), key.y + 25, paint);
        }
    }
}

you can change the position by changing the x and y parameters.

enjoy :)

Yakov
  • 481
  • 5
  • 11
  • 1
    Hi @Yakov can you help me to solve this problem, I am getting NullPointerException when my control reaches at below line, canvas.drawText("1", key.x + (key.width/2), key.y + 25, paint); – Aniket Oct 19 '13 at 06:34