Masking Input in EditText in Android

心不动则不痛 提交于 2019-12-11 10:19:46

问题


How to use inputfilter for CNIC i.e #####-#######-# ? Please help me.. I am new to Android and I dont know how to use it?

How to mask input? I went through various sites but couldn't find solution. I am so confused.


回答1:


Have you tried using Masked EditText ? This is what you want ... :)

If you want a numeric keyboard instead of alphabetical, then comment the following lineof code:

this.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

in the file MaskedEditText.java. Now setting android:inputType = "numeric" will work.




回答2:


) You can also try the fork of Masked EditText. It's derived but with works with Gradle, has some bugfixes, an example project, and a little bit another behavior :-)

The behavior is also changed:

  1. You can set the flag and the hint will be always visible.
  2. Your pattern is invisible initially and grows automatically as soon, as you type. For instance, in the beginning, it is: "+7(", then you type '999' and it shows you "+7(999)" with another brace. In the original library, AFAIK it works like: "+7( ) - - ", then you type '999' and it transforms into "+7(999) - - " and so on.


来源:https://stackoverflow.com/questions/27120695/masking-input-in-edittext-in-android

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