Custom keyboard - Android

2019-03-03 02:02发布

问题:

Is there any known combinations of inputTypes on an inputText that would give a Num-pad keyboard with special characters such as $, *, # and &. I am trying to allow the user to input a number and that field could take the mentioned characters as well. I have tried many but none seem to be giving the required output.

Would I have to create my own custom keyboard for this? Since my request is very specific to certain special characters please do not mark this as a duplicate question. Thanks in advance.

回答1:

You can use KeyboardView to for customizing as your need.

KeyboardView customKeyboard = new KeyboardView(context);
customKeyboard.setKeyboard(new Keyboard(this, R.xml.customLayout));

customKeyboard.setOnKeyboardActionListener(new OnKeyboardActionListener() {
    //do your work here
}

Where R.xml.customLayout refers to /res/xml/customLayout.xml. A very good tutorial for customizing a keyboard is..

  • create-your-own-custom-keyboard-for.html

Which will help you much better.