androidkotlin

How to adjust the layout in API36?


My app targeted on API 34. All text can show properly without shielded by the camera or home button. API 30, All the button can properly shown and functioned.

When API 36 implemented, some of the content is covered by the front camera and home button, how can I adjust the layout so as to show the contents properly?

API 36, the heading is covered by the camera, and the bottom will be covered by home button.


Solution

  • There are two alternative solutions to your issue:

    1. You can try to use android:fitsSystemWindows="true" in your xml layout. This solution is easy but does not work with all kind of layouts, so you have to try and test it.
    2. Implement in the code the handling of insets using ViewCompat.setOnApplyWindowInsetsListener as described in Display content edge-to-edge in views. This solution requires more coding, but can handle better specific layouts. In the second solution don't set fitsSystemWindows in layout.

    Solution 1 worked only on some of my apps with very simple layouts, solution 2 worked also in case of complex scenarios.