Open a numeric keyboard without forcing the EditText to be numeric only

断了今生、忘了曾经 提交于 2019-12-19 06:33:15

问题


I've come across this while doing work on creating my own Keyboard but can't for the life of me remember where I ran across it.

I want top open the Numeric keyboard. However, I want my EditText to only accept an IP address. Adding a filter to my EditText wasn't too hard thanks to this answer.

However, now I want to make the Numeric keyboard to open rather than the standard text keyboard. Unfortunately search results are saturated with the same "How do you limit EditText to numeric input?" questions over and over.

Could anyone point me to the right place for manually opening the Numeric Keyboard.


回答1:


Not sure if this is the best solution, but I use android:inputType="phone".




回答2:


8 days late but alrighty!

android:inputType="number"

works for me. Of course Glitch's answer might be better given that not all keyboards have a numeric input style. And of course you'll still have to validate it




回答3:


Adding to the existing solution, if you want to restrict to just numbers and dots, you can add

android:digits="0123456789."

to the xml of the EditText. So combining the current solution and the above:

android:inputType="phone"
android:digits="0123456789."

will make sure you are able to just put IP address related stuff in the EditText. Now, when the keyboard comes up it has the T9 letters on the keys, but that's a function of the "phone" inputType. Also, you'll have to make sure it's a valid IP after entry.




回答4:


or you can also go for

editext ss;
ss.setInputType(InputType.TYPE_CLASS_NUMBER);


来源:https://stackoverflow.com/questions/8476490/open-a-numeric-keyboard-without-forcing-the-edittext-to-be-numeric-only

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