Question

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

Was it helpful?

Solution

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 :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top