开发者

How can you configure an EditText's soft keyboard to use numbers initially, but still allow text?

开发者 https://www.devze.com 2023-01-08 02:46 出处:网络
I want to let users input a postal code to my app.The common use case is the US zip code, which are composed solely of numbers, so I\'d like to display the numeric keyboard initially in the soft input

I want to let users input a postal code to my app. The common use case is the US zip code, which are composed solely of numbers, so I'd like to display the numeric keyboard initially in the soft input. However, not all postal codes are solely digits, so I still need users to be able to enter other characters.

I've been trying to do this with android:inputType, but by setting the "number" flag, it automatically blocks any input except for number-based stuff. Is there a way to just accept general tex开发者_开发技巧t, but get the soft keyboard to initially display a more number-based keyboard?


Have you tried initially setting the inputType to "number" and then via a TextWatcher changing the input type of the TextView programatically?

0

精彩评论

暂无评论...
验证码 换一张
取 消