Android 键盘弹出和关闭事件

public void toggleSoftInput(View et) {
        et.requestFocus();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);


}

//关闭键盘

/*InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.hideSoftInputFromWindow(ContentText.getWindowToken(), 0);*/


//关闭键盘

retractInputBox(ContentText);

private void retractInputBox(View view){
InputMethodManager imm = (InputMethodManager)view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);  
if(imm.isActive()){  
imm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0 );  
}
}

你可能感兴趣的:(android)