简体   繁体   中英

Disable comma or dot based on device locale in android

How can I disable dot(.) key or comma(,) key in android based on the locale language selected on the device. I need to use dot for English and comma for Swedish or other languages that support comma instead of dot.

You can use DigitsKeyListener from Android.

For Ex,

If English,

editText.setKeyListener(DigitsKeyListener.getInstance("abcdefghijklmnopqrstuvwxyz1234567890."));

If swedish,

editText.setKeyListener(DigitsKeyListener.getInstance("abcdefghijklmnopqrstuvwxyz1234567890,"));

Note that this EditText will only accepts the characters you specified in this String. So whatever chars you want you have to add it to here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM