//必须
relative.setOnTouchListener(new OnTouchListener() {relative.requestFocus();
return false;if (remove_btn.hasFocus() == false) {
//失去焦点时做某事
}
}
}
父控件设置下面属性,拦截焦点即可
EditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter( length) ,emjorFilter});// 设置输入最大字符数 // 过滤输入法表情 public InputFilter emjorFilter = new InputFilter() { Pattern emoji = Pattern .compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff ]",Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE); @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,int dend) { Matcher emojiMatcher = emoji.matcher(source); if (emojiMatcher.find()) { return ""; } return null; } };
EditText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) { // TODO Auto-generated method stub return (arg2.getKeyCode() == KeyEvent.KEYCODE_ENTER); } });