Код: Выделить всё
//
// Fragment's code.
//
private void edgeToEdge() {
final Rect topLinearLayoutInitialPadding = new Rect(
topLinearLayout.getPaddingLeft(),
topLinearLayout.getPaddingTop(),
topLinearLayout.getPaddingRight(),
topLinearLayout.getPaddingBottom()
);
final Rect scrollViewInitialPadding = new Rect(
scrollView.getPaddingLeft(),
scrollView.getPaddingTop(),
scrollView.getPaddingRight(),
scrollView.getPaddingBottom()
);
final Rect bottomFrameLayoutInitialPadding = new Rect(
bottomFrameLayout.getPaddingLeft(),
bottomFrameLayout.getPaddingTop(),
bottomFrameLayout.getPaddingRight(),
bottomFrameLayout.getPaddingBottom()
);
// 2. Apply a listener to handle window insets for all orientations
ViewCompat.setOnApplyWindowInsetsListener(this.getView(), (v, insets) -> {
// Get the insets for the system bars (status bar, navigation bar)
Insets theInsets = insets.getInsets(
WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout() | WindowInsetsCompat.Type.ime()
);
topLinearLayout.setPadding(
topLinearLayoutInitialPadding.left + theInsets.left,
topLinearLayoutInitialPadding.top + 0,
topLinearLayoutInitialPadding.right + theInsets.right,
topLinearLayoutInitialPadding.bottom + 0
);
scrollView.setPadding(
scrollViewInitialPadding.left + theInsets.left,
scrollViewInitialPadding.top + 0,
scrollViewInitialPadding.right + theInsets.right,
scrollViewInitialPadding.bottom + 0
);
bottomFrameLayout.setPadding(
bottomFrameLayoutInitialPadding.left + theInsets.left,
bottomFrameLayoutInitialPadding.top + 0,
bottomFrameLayoutInitialPadding.right + theInsets.right,
bottomFrameLayoutInitialPadding.bottom + theInsets.bottom
);
// Return the insets to allow the system to continue processing them
return insets;
});
}
//
// Activity's code
//
private void setOnApplyWindowInsetsListener() {
final Rect initialPadding = new Rect(
toolbarFrameLayout.getPaddingLeft(),
toolbarFrameLayout.getPaddingTop(),
toolbarFrameLayout.getPaddingRight(),
toolbarFrameLayout.getPaddingBottom()
);
// 2. Apply a listener to handle window insets for all orientations
ViewCompat.setOnApplyWindowInsetsListener(toolbarFrameLayout, (v, insets) -> {
// Get the insets for the system bars (status bar, navigation bar)
Insets theInsets = insets.getInsets(
WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout()
);
v.setPadding(
initialPadding.left + theInsets.left,
initialPadding.top + 0,
initialPadding.right + theInsets.right,
initialPadding.bottom + 0
);
// Return the insets to allow the system to continue processing them
return insets;
});
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... scape-mode