How can you make a custom keyboard in Android?

前端 未结 9 2127
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 04:42

I want to make a custom keyboard. I don\'t know how to do it using XML and Java. The following picture is a model of the keyboard I want to make. It only needs numbers.

9条回答
  •  不思量自难忘°
    2020-11-22 05:28

    Use KeyboardView:

    KeyboardView kbd = new KeyboardView(context);
    kbd.setKeyboard(new Keyboard(this, R.xml.custom));
    
    kbd.setOnKeyboardActionListener(new OnKeyboardActionListener() {
        ....
    }
    

    now you have kbd which is a normal view.

    The nice thing about this is that R.xml.custom refers to /res/xml/custom.xml, which defines in xml the layout of the keyboard. For more information on this file, look here: Keyboard, Keyboard.Row, Keyboard.Key.

提交回复
热议问题