WindowInsets Handling & Keyboard Animations

Jul 20 2021 Kotlin 1.5.10, Android 11, Android Studio 4.1.3 and Android Studio Arctic Fox Canary 12

Part 1: Keyboard Handling in Android

2. Read the Keyboard Visibility

Lesson Complete

Play Next Lesson
Next
Save for later
About this episode
See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 1. Introduction to Keyboard Properties in Android Next episode: 3. Read the Keyboard Height

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

It’s time to dive in and start making some changes.

val imm = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(binding.etContent.windowToken, InputMethodManager.SHOW_FORCED)
view?.windowInsetsController?.hide(WindowInsetsCompat.Type.ime())
val imm = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(binding.etContent, InputMethodManager.SHOW_FORCED)
view?.windowInsetsController?.show(WindowInsetsCompat.Type.ime())
view?.rootWindowInsets?.isVisible(WindowInsetsCompat.Type.ime())
binding.etContent.requestFocus()
fun closeKeyboard(view: View)
@RequiresApi(Build.VERSION_CODES.R)
fun closeKeyboard(view: View) {
  if (view.rootWindowInsets?.isVisible(WindowInsetsCompat.Type.ime()) == true) {
    view.windowInsetsController?.hide(WindowInsetsCompat.Type.ime())
  }
}
fun closeKeyboard(view: View) {
  view.clearFocus()
}
override fun closeKeyboard(view: View) {
  if (isAtLeastAndroid11()) {
    rwCompat11.closeKeyboard(view)
  } else {
    rwCompat10.closeKeyboard(view)
  }
}
setOnTouchListener { _, _ ->
  rwCompat.closeKeyboard(binding.etContent)
  false
}