Prasath S
Prasath S

Reputation: 4416

Android IME, use custom layout instead of Keyboard and support KeyboardView's setKeyboard and setOnKeyboardActionListener listeners

I'm creating a custom keyboard in android but in android to create a custom keyboard we need to pass the keyboard XML to generate the keyboard view(XML code below). I want to design my own keyboard using layouts that should like to support the KeyboardView's setKeyboard() and setOnKeyboardActionListener(), How can I do that? Thanks in Advance

@Override
    public View onCreateInputView() {

        KeyboardView keyboardView=(KeyboardView) getLayoutInflater().inflate(R.layout.keyboard_view,null);

        Keyboard keyboard=new Keyboard(this,R.xml.numberpad);
        keyboardView.setKeyboard(keyboard);
        keyboardView.setOnKeyboardActionListener(this);

        return keyboardView;
}

current XML numberpad

<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
    android:keyWidth="10%p"
    android:horizontalGap="2dp"
    android:verticalGap="2dp"
    android:keyHeight="55dp"
    android:keyTextColor="@color/design_default_color_primary"
    android:keyBackground="@drawable/ic_baseline_keyboard_24">
    <Row>
        <Key android:codes="49" android:keyLabel="1" android:keyEdgeFlags="left"/>
        <Key android:codes="50" android:keyLabel="2"/>
        <Key android:codes="51" android:keyLabel="3"/>
        <Key android:codes="52" android:keyLabel="4"/>
        <Key android:codes="53" android:keyLabel="5"/>
        <Key android:codes="54" android:keyLabel="6"/>
        <Key android:codes="55" android:keyLabel="7"/>
        <Key android:codes="56" android:keyLabel="8"/>
        <Key android:codes="57" android:keyLabel="9"/>
        <Key android:codes="48" android:keyLabel="0"/>
    </Row>

</Keyboard>

Upvotes: 0

Views: 332

Answers (0)

Related Questions