Android custom keyboard with 2 lablels (main and small at the top right)

筅森魡賤 提交于 2019-12-06 10:51:08

问题


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

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


回答1:


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



来源:https://stackoverflow.com/questions/18738452/android-custom-keyboard-with-2-lablels-main-and-small-at-the-top-right

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!