5/05/2014

Android - 키보드 보이기, 숨기기

일단 키보드가 제대로 안나타난다면 이전 포스트에서 언급한 것을 떠올려보자.

 키보드가 자체가 사라지는 문제는 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

댓글 없음:

댓글 쓰기