How to check visibility of software keyboard in Android?

前端 未结 30 4433
半阙折子戏
半阙折子戏 2020-11-21 04:43

I need to do a very simple thing - find out if the software keyboard is shown. Is this possible in Android?

30条回答
  •  既然无缘
    2020-11-21 05:11

    There is a direct method to find this out. And, it does not require any Layout changes.
    So, it works in immersive fullscreen mode, too.

    The trick is that you try to hide or show the soft keyboard and capture the result of that try.
    No panic, this does not really show or hide the keyboard. We just ask for the state.

    To stay up-to-date, you can simply repeat the operation, e.g. every 200 milliseconds, using a Handler.

    You find an implementation here: https://stackoverflow.com/a/27567074/2525452

提交回复
热议问题