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

前端 未结 4 1681
误落风尘
误落风尘 2021-01-12 09:31

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 Nu

相关标签:
4条回答
  • 2021-01-12 09:51

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

    0 讨论(0)
  • 2021-01-12 09:53

    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.

    0 讨论(0)
  • 2021-01-12 10:04

    or you can also go for

    editext ss;
    ss.setInputType(InputType.TYPE_CLASS_NUMBER);
    
    0 讨论(0)
  • 2021-01-12 10:16

    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

    0 讨论(0)
提交回复
热议问题