admin管理员组

文章数量:1334920

When I use EdgeToEdge.enable(this); in the onCreate() method of my activity, it allows my activity to occupy the entire screen of the phone, including the space of the status bar and the navigation bar.

However, as soon as I switch to full screen, the layout shrinks, the status bar area turns black, and I can no longer display anything in that area.

I’ve tried several solutions to resolve this issue, including:

getWindow().getDecorView().setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_FULLSCREEN
        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_IMMERSIVE
);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    getWindow().setDecorFitsSystemWindows(false);
    WindowInsetsController controller = getWindow().getInsetsController();
    if (controller != null) {
        controller.hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
        controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
    }
}
getWindow().setFlags(
        WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN
);

But nothing works. In all cases, my layout loses the upper part of the screen.
This happens on my phone, a Pixel 8 Pro running Android 15, but I know it’s not a phone bug because some apps like WhatsApp and Google Photos can display photos in full screen without a status bar. And this is exactly what I’m trying to replicate.

Do you have any idea?

When I use EdgeToEdge.enable(this); in the onCreate() method of my activity, it allows my activity to occupy the entire screen of the phone, including the space of the status bar and the navigation bar.

However, as soon as I switch to full screen, the layout shrinks, the status bar area turns black, and I can no longer display anything in that area.

I’ve tried several solutions to resolve this issue, including:

getWindow().getDecorView().setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_FULLSCREEN
        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_IMMERSIVE
);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    getWindow().setDecorFitsSystemWindows(false);
    WindowInsetsController controller = getWindow().getInsetsController();
    if (controller != null) {
        controller.hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
        controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
    }
}
getWindow().setFlags(
        WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN
);

But nothing works. In all cases, my layout loses the upper part of the screen.
This happens on my phone, a Pixel 8 Pro running Android 15, but I know it’s not a phone bug because some apps like WhatsApp and Google Photos can display photos in full screen without a status bar. And this is exactly what I’m trying to replicate.

Do you have any idea?

Share Improve this question asked Nov 20, 2024 at 19:32 KazuyaKazuya 654 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

After almost two weeks of struggle, I figured out that I just had to do this during the activity initialization:

WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        this.getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}

本文标签: androidAdroid StudioFullscreen with full layoutStack Overflow