Могу ли я узнать, есть ли наилучшая практика или официальный способ обработки в API 35, в частности, в режиме ландшафта? alt = "Введите описание изображения здесь" src = "https://i.sstatic.net/xv22nzhi.png"/>
//
// 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;
});
}
Напротив, макет приложения настройки Google в режиме ландшафта, по-видимому, использует гораздо более простой подход. Для рекомендованного или официального способа достижения режима до края в режиме ландшафта API 35?
Могу ли я узнать, есть ли наилучшая практика или официальный способ обработки в API 35, в частности, в режиме ландшафта? alt = "Введите описание изображения здесь" src = "https://i.sstatic.net/xv22nzhi.png"/> [code]// // 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() );
// 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() );
// Return the insets to allow the system to continue processing them return insets; }); } [/code] Напротив, макет приложения настройки Google в режиме ландшафта, по-видимому, использует гораздо более простой подход. Для рекомендованного или официального способа достижения режима до края в режиме ландшафта API 35?