Dauris Little
all
  • About
  • Dauris’s Portfolio
  • Blogging Lyf
  • Contact
© 2016 Dauris Little. All rights reserved.
  • Home
  • Blog
  • Programming Languages
  • Android
  • Show/Hide On-Screen Keyboard
November 12, 2025

BLOG & Gossip

Avatar photo
Dauris
Friday, 11 December 2020 / Published in Android, Java, Kotlin, Programming Languages

Show/Hide On-Screen Keyboard

Android R is also known as Android 11 release brought a few new APIs to the table and one of them is the new WindowInset which expands the control that we as developers have over the window insets. This includes the navigation and status bar as well as an on-screen keyboard.

This new release provides a direct way to check these state changes that now toggle and listen for changes in the visibility of the window insets. These options now allow the developer to control and react to the animation when the visibility state changes (but this is not going to be covered within this article).

Getting Started

When writing this post, Android 11 been running on more than 1% of devices, but thanks to the magic of AndroidX the APIs are also usable on several other devices with earlier versions. This post focus on using AndroidX implementation but you will find the equivalent APIs to use in documentation.

implementation "androidx.core:core-ktx:1.5.0-alpha05

Now we are going to insert the following code into the build.gradle file, under all the dependencies. (Note: Any version of 1.5.0 or later will work and please check for the latest version. Apply accordingly)

Show/Hide Keyboard

To start we need to access the WindowInsetsController. When the view is passed it doesn’t have to be an EditText directly but can be any view in the same hierarchy as the focused editText.

//note: ci is my shorthand for controllerInsets
val ci = ViewCompat.getWindowInsetsController(view)

Now that we have initialized the view let show the keyboard on the screen:

ci?.show(WindowInsetsCompat.Type.ime())

Let’s hide the keyboard now:

ci?.hide(WindowInsetsCompat.Type.ime())

Keyboard Visibility

If you have ever tried to check the keyboard visibility in the past then you have probably messed with the global layout listeners because there was no other way. Well, hold on to your trousers because finally there is a proper way to do it.

//start by accessing the root window insets
val insets = ViewCompat.getRootWindowInsets(view)

//Now check the visibility of the IME window
insets?.isVisible(WindowInsetsCompat.Type.ime())

Catching Keyboard Changes

To catch the changes with the keyboard visibility, then we have to let the device know that the app is now responsible for the content view of the insets.

//add the following now
WindowCompat.setDecorFitsSystemWindows(window, false)

This will force the view to be drawn behind the on-screen keyboard as well as other system UI, however, now that we are listening for the keyboard changes we can move any other conflicting views accordingly.

Conclusion

Controlling the on-screen keyboard is common in Android development, so the APIs are long overdue. Understand that this now provides us (developers) a more reliable and efficient way to control any type of window insets going forward. Also, note that AndroidX allows us to use these APIs with older Android versions as well.

  • Tweet
Tagged under: android, android development, android keyboard, androidx, java, kotlin

What you can read next

Android w/ Fragments
navigation drawer
Android Navigation Drawer
Using Enum w/Swift

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Categories

Recent Posts

  • Gesture Controls for Android w/Kotlin

    Incorporating Gesture controls in your android ...
  • Android Rating: In-App Review API

    An app rating and reviews are crucial if you wa...
  • QR Reader in Android w/ Kotlin

    Turn your phone's camera into a QR scanner...
  • Creating Advance Custom Snackbar w/ Kotlin

    Ask 100 different developers about what they fi...
  • Swift Has Tuple

    Swift provides us with a type called Tuple whic...

Recent Comments

  • Homepage on Integrating Google’s reCAPTCHA w/Android
  • Cleora Weideman on Integrating Google’s reCAPTCHA w/Android
  • alpha femme keto Reviews on Integrating Google’s reCAPTCHA w/Android
  • best skin care products reviews on Integrating Google’s reCAPTCHA w/Android
  • Robyn on Integrating Google’s reCAPTCHA w/Android

Archives

  • January 2022
  • December 2021
  • September 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • October 2020
  • August 2020
  • July 2020
  • May 2020
  • March 2020
  • February 2020
  • December 2019
  • October 2019
  • September 2019
  • May 2019
  • March 2019
  • February 2019
  • January 2019
  • August 2018
  • April 2018
  • August 2017
  • November 2016
  • August 2016

Categories

  • .NET & .NET Core
  • Active Directory
  • Android
  • API
  • bitcoin
  • blog
  • C#
  • Development
  • E-Commerce
  • HTML5
  • iOS
  • Java
  • Javascript
  • Kotlin
  • Language
  • Like I Am Five
  • Mobile Development
  • New Web Site
  • Programming Languages
  • Swift
  • Tutorial
  • Uncategorized
  • Web Application Development
  • Windows AD

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

© 2015. All rights reserved. Buy Kallyas Theme.

TOP
This site uses tracking cookies to personalize content and ads. AcceptLearn More