The ability to use translucent in android appeared in KITKAT . And it looks in the right design is pretty impressive. And with the advent of fashion for devices with “Bangs”, it seems to be just a necessary thing in any warm tube startups.
Let’s imagine a situation: you’ve written down a stunningly beautiful design that scrolls under StatusBar and NavigationBar. And here you add an input field and understand that adjustResize does not work for you.
You can:
There are several difficulties with translucent implementation:
It seems to be a simple solution: adjustResize does not work, it means that you have to respond to the opening of the claviarot yourself. But the trouble android does not provide not only the height of the keyboard (and it may be different even for different EditText fields), but even the fact of its opening or closing. There is no official way. How so google?
Of course there is a solution! And when you have information about the current height of the keyboard, you can do with it what you want: add padding or margin to the bottom for those View, which should respond to the keyboard and now custom adjustResize is ready.
To understand that the keyboard has been opened, use OnGlobalLayoutListener . Embed pieces of code in the post does not see the point. Why write 100 lines about what is expressed in code over 50?
The solution to the problem is presented in the repository .
Take a closer look at KeyboardHeightProvider and BaseTranslucentActivity .
The project is as simple as possible, understandable, there is nothing superfluous in it that is not related to the problem.
There is an example for a simple TextView, RecyclerView and ScrollView. The same technique was tested and works fine for NestedScrollView, NestedFragments, CoordinatorLayout, ViewPager, etc.
Ps: https://developer.android.com/reference/android/view/WindowInsets solves the problem with the keyboard as well.
Source: https://habr.com/ru/post/436646/