Руководство Android < /p>
блог < /p>
метод, который я использую. < /p>
Код: Выделить всё
private void edgeToedge() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){
EdgeToEdge.enable(this);
WindowInsetsControllerCompat windowInsetsController =
ViewCompat.getWindowInsetsController(getWindow().getDecorView());
if (windowInsetsController == null) {
return;
}
windowInsetsController.setAppearanceLightNavigationBars(true);
WindowCompat.getInsetsController(getWindow(),getWindow().getDecorView())
.setAppearanceLightStatusBars(true);
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
ViewCompat.setOnApplyWindowInsetsListener(toolbar, new OnApplyWindowInsetsListener() {
@NonNull
@Override
public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat insets) {
// Retrieve the insets for the system bars (status bar, nav bar, etc.)
Insets systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars());
// Update layout params: add a top margin equal to the status bar height.
ViewGroup.LayoutParams lp = v.getLayoutParams();
if (lp instanceof ViewGroup.MarginLayoutParams) {
ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) lp;
marginParams.topMargin = systemBarsInsets.top;
v.setLayoutParams(marginParams);
}
// Alternatively, you can update padding if that better suits your design:
// v.setPadding(v.getPaddingLeft(), originalPaddingTop + systemBarsInsets.top,
// v.getPaddingRight(), v.getPaddingBottom());
return insets;
}
});
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... ge-to-edge
Мобильная версия