0

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>
FGH
  • 2,900
  • 6
  • 26
  • 59
  • Did you see: [How can you make a custom keyboard in Android?](https://stackoverflow.com/q/9577304/295004) – Morrison Chang Jan 07 '23 at 06:06
  • my question is different, thank you for your reply – FGH Jan 07 '23 at 06:34
  • To me you question seems like you want to create different layouts than what is supported by `` in which case you are doing a custom keyboard and may be interested in the `Going On` section of [this answer](https://stackoverflow.com/a/44939816/295004) at the bottom. – Morrison Chang Jan 07 '23 at 06:59
  • in that answer also they are using `Keyboard`, but in my case, I want to create a custom layout file, I'm expecting to create a class and extend the KeyboardPreview and passing the created layout file, but in this approach I'm facing some issue – FGH Jan 07 '23 at 07:33
  • I don't think you can use custom layouts with [KeyboardView](https://developer.android.com/reference/android/inputmethodservice/KeyboardView) as it has been [deprecated](https://stackoverflow.com/q/60316785/295004). So you'll have to take the [AOSP source](https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/java/android/inputmethodservice/KeyboardView.java) and make your own. – Morrison Chang Jan 07 '23 at 07:59

0 Answers0