private EditText name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
name = findViewById(R.id.loginname);
name.setFilters(new InputFilter[]{
new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
for (int i = start; i < end; i++) {
if ( !Character.isLetterOrDigit(source.charAt(i))
&& !Character.toString(source.charAt(i)) .equals("_")
&& !Character.toString(source.charAt(i)) .equals("-"))
{
return "";
}
}
return null;
}
}
});
}
Android限制EditText只能输入中文、英文、数字
最新推荐文章于 2024-07-10 13:50:58 发布