Android 11 introduces new APIs to improve transitions for input method editors (IMEs), such as on-screen keyboards. These APIs make it easier to adjust your app's content in synchronization with the IME's appearance and disappearance, and with other elements like the status and navigation bars.
To show an IME while any EditText has the focus, call view.getInsetsController().show(Type.ime()). (You can call this method on any view in the same hierarchy as the focused EditText, you don't have to call it on the EditText specifically.) To hide the IME, call view.getInsetsController().hide(Type.ime()). You can check whether an IME is currently visible by calling view.getRootWindowInsets().isVisible(Type.ime()).
To synchronize your app's views with the appearance and disappearance of the IME, set a listener on a view by providing a WindowInsetsAnimation.Callback to View.setWindowInsetsAnimationCallback(). (You can set this listener on any view, it doesn't have to be an EditText.) The IME calls your listener's onPrepare() method, then it calls onStart() at the beginning of the transition. It then calls onProgress() at each progression in the transition. When the transition has finished, the IME calls onEnd(). At any point in the transition, you can find out how much progress the transition has made by calling WindowInsetsAnimation.getFraction().
For an example of how to use these APIs, see the new WindowInsetsAnimation code sample.
- Check feability to refactor our IME to use the new APIs. It is added to Compat, so it is backward compatible.