키보드가 자체가 사라지는 문제는 manifest의
android:windowSoftInputMode="adjustPan"
가 핵심이다.
/**
* Hides the soft keyboard
*/
public void hideSoftKeyboard() {
if(getCurrentFocus()!=null) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
}
/**
* Shows the soft keyboard
*/
public void showSoftKeyboard(View view) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
view.requestFocus();
inputMethodManager.showSoftInput(view, 0);
}
showSoftKeyboard 의 파라미터 없이 직접 원하는 view를 넣어도 된다.
Reference : http://stackoverflow.com/questions/18977187/how-to-hide-soft-keyboard-when-activity-starts
댓글 없음:
댓글 쓰기