Translucent to Android and adjustResize
The ability to use translucent in android appeared even 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.
- To score, - the user will close the keyboard himself to see what is under it.
- Abandon translucent , style is not yours, everything will be old, reliable, like everyone else.
- As soon as the user starts scrolling, hide the keyboard. You are well done! All right, skype even under ios does it! And there is no transparency.
- Move all input fields to separate screens. As a bonus - every extra transition to the screen, minus convenience and conversion.
- Cut down your adjustResize .
All translucent complexity
There are several difficulties with translucent implementation :
- It is necessary to take into account the design for devices less KITKAT (I think that in 2019, this is almost irrelevant, especially for new projects). Perhaps, for devices less than LOLLIPOP can a game of candle is not worth it? You can’t get transparent NavigationBar and “Man” on such devices either.
- If you are thinking about translucent , then most likely you want something more complicated than a static background, something scrolling under the StatusBar and NavigationBar, something that you can not do with fitsSystemWindows , which means you have to substitute the height of the StatusBar and NavigationBar dynamically.
- And finally, the main thing: adjustResize works only without translucent or for those View which fitsSystemWindows .
What it is about and how it should work
Solution to the problem
It seems to be a simple solution: adjustResize does not work , it means that it is necessary to react to the opening of the claviarot itself. 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.