如何强制EditText只接受特定的字母数字字符? [英] How to force EditText to accept only specific alphanumerical characters?

查看:74
本文介绍了如何强制EditText只接受特定的字母数字字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的EditText中仅接受某些字符.我不想在侦听器中过滤它们,而是想在XML中永久设置它.

I want from my EditText to accept only certain characters. I don`t want to filter them in listener, I want to set it in XML permanently.

我只想使用以下字符: 0123456789abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ

I want to use only these characters: 0123456789abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ

所以我制作了字符串并将其添加到android:digits. 我想将每个小写字母都转换为大写字母(我不想禁用输入而不转换,只需将它们转换)

So I made string and add that to android:digits. I want to convert each lowercase letter to uppercase (I dont want to disable typing without shift just convert them)

我使用了android:textAllCaps="true",但是这不起作用.

I used android:textAllCaps="true" but this doesnt work.

推荐答案

尝试一下,这将对您有所帮助.

Try this, This will help you for sure.

 editText.setFilters(new InputFilter[] {new InputFilter.AllCaps()});

这篇关于如何强制EditText只接受特定的字母数字字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆