What android:inputType should I use for entering an IP Address and hostname?

I am building a small Android app where the user will enter an IP address or a hostname into an widget. 90% of the time they will be entering an IP address, the rest of the time - a hostname.EditText

So naturally, I want to make it easy for them to enter an IP address, but the ability to switch to alpha numerics for hostname entry is important.

I can't seem to find a good inputType. The initially seemed like a good shot, but it only allows one dot.numberDecimal

Ideally, I'd like to start with a standard keyboard that had the button pressed.?123

How do I get there?


答案 1

Try using , but also set . Works for me.android:inputType="number"android:digits="0123456789."


答案 2

If you use you gain access to a cut down keyboard containing Numbers and a Period character - this doesn't restrict the input with regards to the amount of Periods you can enter.inputType="phone"

Please see this answer for validation while being entered.


推荐