在我的 Android 应用程序中,我有不同的 EditText
用户可以在其中输入信息.但我需要强制用户用大写字母书写.你知道这样做的功能吗?
In my Android application I have different EditText
where the user can enter information. But I need to force user to write in uppercase letters.
Do you know a function to do that?
Android其实有一个内置 InputFilter 就是为了这个!
Android actually has a built-in InputFilter just for this!
edittext.setFilters(new InputFilter[] {new InputFilter.AllCaps()});
小心,setFilters
将重置通过 XML 设置的所有其他属性(即 maxLines
、inputType
,imeOptinos
...).为防止这种情况发生,请将您的过滤器添加到现有的过滤器中.
Be careful, setFilters
will reset all other attributes which were set via XML (i.e. maxLines
, inputType
,imeOptinos
...). To prevent this, add you Filter(s) to the already existing ones.
InputFilter[] editFilters = <EditText>.getFilters();
InputFilter[] newFilters = new InputFilter[editFilters.length + 1];
System.arraycopy(editFilters, 0, newFilters, 0, editFilters.length);
newFilters[editFilters.length] = <YOUR_FILTER>;
<EditText>.setFilters(newFilters);
这篇关于在Android EditText中,如何强制写大写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!