How can I default to the numeric keypad on focus of an EditText view?

大城市里の小女人 提交于 2019-12-14 03:57:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!