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());