当有控件获得焦点focus 自动弹出键盘
1.点击软键盘的enter键 自动收回键盘
2.代码控制 InputMethodManager
showSoftInput:显示键盘 必须先让这个view称为焦点requestFocus
java代码如下:
EditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus == true){
//焦点存在
}else{
//焦点不存在
}
}
});
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
View focusView = getCurrentFocus();
if(focusView != null){
focusView.clearFocus();//取消焦点
}}
return true;
}