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

02. 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: 01. Introduction to Keyboard Properties in Android Next episode: 03. Read the Keyboard Height

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

Take your career further with a Kodeco Personal Plan. 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.

Notes: 02. Read the Keyboard Visibility

WindowInsets

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

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
}