android: start in symbol keyboard mode, but don't restrict to numbers-only input
I want to specify that Android should start the soft keyboard for a given EditText in the numeric/symbols mode. I know this can be done by setting the input type of the EditText to be numeric using EditText.setInputType() except that I do not want to restrict the input type for the EditText to numeric input only**. Is there another way to tell Android what keyboard it should open f开发者_如何学JAVAor a given EditText?
** I want essentially a Math class of numeric input, accepting arbitrary mathematical expressions, including [0,9.+-/*()@:].
After some research and trying lots of different things, I found the answer:
editField.setRawInputType(InputType.TYPE_CLASS_NUMBER);
// ^^^ note the Raw!
So you need the Raw version of setting the input type to circumvent a KeyListener being set, which restricts the input.
I believe the magic is in:
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
精彩评论