안드로이드에서 화면에 나타난 소프트 키보드를 숨겨요.
1. 함수 살펴보기.
getSystemService 함수에서 InputMethodManager 서비스를 가져와서 hideSoftInputFromWindow 메서드 함수를 실행해요. view.windowToken는 윈도우 토큰으로 IBinder 타입을 반환받아서 인자로 넘겨요.
IBinder는 잠재적으로 null 값을 가지는 상태를 고려하여야 좋겠쩌.
fun hideSoftInput(view: View) {
val inputMethodManager = this.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
val token = view.windowToken
if(token != null){
inputMethodManager.hideSoftInputFromWindow(token, 0)
}
}
developer.android.com - getSystemService
developer.android.com - InputMethodManager
developer.android.com - getWindowToken
댓글이 사용 중지되었습니다.