대상이 되는 EditText
포커싱 및 키보드 등장
더보기
private fun EditText.setFocusAndShowKeyboard(context: Context) {
this.requestFocus()
setSelection(this.text.length)
this.postDelayed({
val inputMethodManager =
context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.showSoftInput(this, InputMethodManager.SHOW_FORCED)
}, 100)
}
포커싱 해제 및 키보드 숨기기
더보기
private fun EditText.clearFocusAndHideKeyboard(context: Context) {
this.clearFocus()
this.postDelayed({
val inputMethodManager =
context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(this.windowToken, 0)
}, 30)
}
'Android > Code' 카테고리의 다른 글
[Project] [Android] [Kotlin] Log Window (0) | 2021.10.18 |
---|---|
[Android] [Kotlin] Google Map (0) | 2021.09.24 |
[Android] [Kotlin] Dialog로 액티비티 띄우기 (0) | 2021.09.15 |
[Android] [Kotlin] chooser Intent (카메라, 갤러리) (0) | 2021.09.12 |
[Android] [Kotlin] 프래그먼트 사용 방법 및 구조 (0) | 2021.09.11 |