Search code examples
androidandroid-softkeyboard

Tell when keyboard with "adjustNothing" opens


In my app I am using the adjustNothing flag to my keyboard. That it a requirement.. Please don't advice me to change it to "resize or pan" :)

My question is if there is any way of knowing when the keyboard opens and closes in this state?

I tried "onGlobalLayout" and "onConfigurationChanged" without any luck. Since the keyboard is not "doing" anything to the app I don't seam to find any way the catch this event.. Please help!


Solution

  • Yes! It's not nice as iOS where you get the height and animation but at least you know that it opens:

    ViewCompat.setOnApplyWindowInsetsListener(findViewById(android.R.id.content), new OnApplyWindowInsetsListener() {
                    @Override
                    public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
    }
    

    This tells you whenever any kind of change happens. It's easy knowing that the keyboard is the reason for that change and act accordingly.