问题
I have an EditText field for the user to enter their weight in lbs. How can I override the traditional keyboard and display the numeric keypad instead?
回答1:
This didn't work for me. However, I was able to accomplish the aforementioned by either of the following lines:
// TYPE_CLASS_NUMBER: Class for numeric text. This displays the numbers/symbols keyboard.
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
// TYPE_CLASS_PHONE: Class for a phone number. This displays the phone number keypad.
editText.setInputType(InputType.TYPE_CLASS_PHONE);
回答2:
This is what i pulled off of the google API
//Set the input style to numbers, rather than qwerty keyboard style.
txtView.setInputMethod(DigitsInputMethod.getInstance());
来源:https://stackoverflow.com/questions/3034287/how-can-i-default-to-the-numeric-keypad-on-focus-of-an-edittext-view