Android 让你的 EditText 只接受指定字符
16lz
2021-01-23
在Android中,让你的EditText只接受你指定的字符,可以用以下办法实现:
NumberKeyListener myKeyListener =
new NumberKeyListener() {
public int getInputType() {
//指定键盘类型
return InputType.TYPE_CLASS_TEXT;
}
protected char[] getAcceptedChars() {
//指定你所接受的字符
return "abcdefg".toCharArray();
}
};
EditText tv = (EditText)findViewById(R.id.testEdit);
tv.setKeyListener(myKeyListener);
你可以将字符串"abcdefg"换成任意的,你想让你的EditText所接受的字符组合。
更多相关文章
- Android中判断字符串中必须包含字母或者数字_Android
- android 复制、粘贴字符串 (判断API 11 )
- NDK编译Android字符界面的可执行程序
- Android 4.0+ 版本中的EditText字符重叠问题
- Android实现TextView字符串波浪式跳动
- Android的数据处理:使用annotation实现JSON字符串解析为java对象
- android 反转字符串
- android 关于字符转化问题