String phoneNumber = "1234567890";
String text = String.valueOf( android.telephony.PhoneNumberUtils.formatNumber(phoneNumber) ); //formatted: 123-456-7890
editTextMobile.setText(text); //set editText text equal to new formatted number
editTextMobile.setSelection(text.length()); //move cursor to end of editText view
在 onKey 功能中使用此功能可以获得带有格式化电话号码的美味动态兔子性爱 .
20
我知道在Android Studio的Android程序中使用EditText上的掩码的最简单方法是使用 MaskedEditText 库(GitHub link) . 它's a kind of custom EditText with Watcher that allows you to set a hint with different color (if you want it will be available even when user already started to type), mask and it'非常好用:-)
6 回答
尝试使用InputFilter而不是
OnKeyListener
. 这意味着您不必担心跟踪单个按键操作,它也会处理诸如粘贴到一个字段中的事情,这将很难处理OnKeyListener
.您可以查看Android附带的source of the InputFilter implementations,为您提供编写自己的起点 .
你可以看一下android.telephony.PhoneNumberFormattingTextWatcher类 . 它使用### - ### - ####模式屏蔽电话号码文本输入 .
在
onKey
功能中使用此功能可以获得带有格式化电话号码的美味动态兔子性爱 .我知道在Android Studio的Android程序中使用EditText上的掩码的最简单方法是使用
MaskedEditText
库(GitHub link) . 它's a kind of custom EditText with Watcher that allows you to set a hint with different color (if you want it will be available even when user already started to type), mask and it'非常好用:-)那就是!
这个site提供了一个很好的2个类,有助于我发现非常有用的掩蔽 .
您需要使用注释中的项目来改进它 . 但值得添加到您的程序,以便轻松屏蔽许多蒙版的EditText视图 .
你可以在EditText中使用这个efect