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

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 1. Introduction to Keyboard Properties in Android Next episode: 3. Read the Keyboard Height

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Pro subscription. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

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

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
}