Dev/Android

Android Keyboard Show Hide

healthyryu 2019. 1. 18. 17:30

Android Keyboard Show Hide




참고 : https://stackoverflow.com/a/5106399/3897810



Activity 의 경우

EditText yourEditText= (EditText) findViewById(R.id.yourEditText);

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);


InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);



Dialog 의 경우

public void showKeyboard(){

    InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

    inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

}


public void closeKeyboard(){

    InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

    inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

}




반응형