在java文件中:
serialText = (EditText) findViewById(R.id.serial_edit);
serialText.setFilters(new InputFilter[] {
new InputFilter.AllCaps(), //自动大写
new InputFilter.LengthFilter(17), //限制字符长度
//只能输入字母和数字
DigitsKeyListener.getInstance("1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM") });
serialText.setTransformationMethod(PasswordTransformationMethod.getInstance()); //设置为密码输入框
serialText.setInputType(InputType.TYPE_CLASS_NUMBER); //输入类型
在布局文件中也能限制长度和限制输入类型:
android:digits="1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
android:maxLength="16"