EditText禁止输空格


1.EditText禁止输空格

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

private InputFilter filter=new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
//返回null表示接收输入的字符,返回空字符串表示不接受输入的字符

if(source.equals(" "))return ""; else return null; }};



2.EditText禁止输空格+换行键

editText.setFilters(new InputFilter[]{filter});
private InputFilter filter=new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if(source.equals(" ")||source.toString().contentEquals("\n"))return "";
else return null;
}
};

上一篇:尝试作图2


下一篇:css 超过两行换行