如何在Android R中设置全屏显示? [英] How to set fullscreen in Android R?

查看:1039
本文介绍了如何在Android R中设置全屏显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的应用中将屏幕全屏显示.为此,我使用以下代码:

I need to put a screen in fullscreen in my app. For this I am using this code:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    requestWindowFeature(Window.FEATURE_NO_TITLE)
    window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN)
    setContentView(R.layout.activity_camera_photo)

但是,不推荐使用WindowManager.LayoutParams.FLAG_FULLSCREEN标志.

However, the WindowManager.LayoutParams.FLAG_FULLSCREEN flag is deprecated.

我的应用程序支持Android Lollipop(API 21)到Android R(API 30). 使屏幕全屏显示的正确方法是什么?

My app supports Android Lollipop (API 21) to Android R (API 30). What is the correct way to make a screen go fullscreen?

推荐答案

KOTLIN

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    @Suppress("DEPRECATION")
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        window.insetsController.hide(WindowInsets.Type.statusBars())
    } else {
        window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
        )
    }
}

如果这没有帮助,请尝试删除布局文件中的android:fitsSystemWindows="true"

if this doesn't help, try to remove android:fitsSystemWindows="true" in the layout file

JAVA

class Activity extends AppCompatActivity {

@Override
@SuppressWarnings("DEPRECATION")
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        final WindowInsetsController insetsController = getWindow().getInsetsController();
        if (insetsController != null) {
            insetsController.hide(WindowInsets.Type.statusBars());
        }
    } else {
        getWindow().setFlags(
                WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN
        );
    }
}
}

这篇关于如何在Android R中设置全屏显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆