Android
[Android] 안드로이드 - 키보드 올리기, 내리기 (soft input)
NukeOlaf
2020. 5. 5. 21:26
* EditText 의 id 가 textInput 이다
키보드 올리기
fun showSoftInput() { val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager inputMethodManager.showSoftInput(textInput, 0) }
키보드 내리기
fun hideSoftInput() { val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager inputMethodManager.hideSoftInputFromWindow(textInput.windowToken, 0) }
* 키보드 올리기, 내리기 작동 안할때
D/InputMethodManager: showSoftInput - cancel : mServedView != view : DecorView@fb022ab[ActivityDetail]
이런 로그가 찍히면서 키보드 올리기/내리기가 제대로 작동하지 않는 경우가 있다.
아래와 같이 EditText에 requestfocus() 를 사용해주면 된다.
fun showSoftInput() { textInput.requestFocus() val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager inputMethodManager.showSoftInput(textInput, 0) }