註冊 InputMethodManager
InputMethodManager imm = ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE));
int SoftInputAnchor = R.id.XX;
顯示 keyboard
imm.toggleSoftInput(SoftInputAnchor, 0);
(需配合 timer 才有作用)
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
imm.toggleSoftInput(SoftInputAnchor, 0);
}
}, 500);
隱藏 keyboard
imm.hideSoftInputFromWindow(
MyActivity.this.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
imm.hideSoftInputFromWindow(
guessEditText.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
// 不自動對焦
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
參考:
http://milochen.wordpress.com/2010/07/23/android-keyboard-startshow-hide-bug/#comments
http://hubingforever.blog.163.com/blog/static/17104057920110751348743/
內建鍵盤
http://blog.csdn.net/liuxiit/article/details/6903884
關閉鍵盤
http://blueredfield.blog.163.com/blog/static/11535200020117983038447/
http://milochen.wordpress.com/2010/07/23/android-keyboard-startshow-hide-bug/
http://4225953-163-com.iteye.com/blog/1235324