Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
statusBar color disappears?
fun isKeyboardVisible(view: View) {
ViewCompat.setOnApplyWindowInsetsListener(view) { view, windowInsets ->
val isKeyboardVisible = windowInsets.isVisible(WindowInsetsCompat.Type.ime())
if (isKeyboardVisible) Toast.makeText(applicationContext, "opened", Toast.LENGTH_SHORT).show()
else Toast.makeText(applicationContext, "closed", Toast.LENGTH_SHORT).show()
windowInsets
Instead of using ViewCompat.setOnApplyWindowInsetsListener(view)
, use window.decorView.setOnApplyWindowInsetsListener
, returning view.onApplyWindowInsets(insets)
like so:
window.decorView.setOnApplyWindowInsetsListener { view, insets ->
//do your thing here
view.onApplyWindowInsets(insets)
And that is it.
Hope it helps!
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.