android - Adroid Studio - Fullscreen with full layout - Stack Overflow

When I use EdgeToEdge.enable(this); in the onCreate() method of my activity, it allows my activity to o

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;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742334487a4424377.html

相关推荐

  • android - Adroid Studio - Fullscreen with full layout - Stack Overflow

    When I use EdgeToEdge.enable(this); in the onCreate() method of my activity, it allows my activity to o

    7小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信