三星 Galaxy S8 全屏模式

Samsung Galaxy S8 full screen mode

最新的三星智能手机有一个有趣的功能,叫做 全屏(或者用营销术语来说 无限显示)。在这种模式下,应用程序还覆盖了 home/back 按钮所在的部分显示。通常的应用程序不会覆盖此区域,将其保留为黑色。但是三星的原生覆盖了这个区域。

提问:如何实现这个效果?我的意思是我应该使用什么样的清单声明或编程调用(可能是三星的遗产 API)?

要获得全屏,您必须覆盖 onWindowFocusChanged 方法并创建 decorView 对象并向其中添加 System_UI 标志。 .

@Override
    public  void onWindowFocusChanged(boolean  hasFocus){
        super.onWindowFocusChanged(hasFocus);
        View decorView = getWindow().getDecorView();
        if(hasFocus){

        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    |View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY  // this flag do=Semi-transparent bars temporarily appear and then hide again
                    |View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN  // Make Content Appear Behind the status  Bar
                    |View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION  // it Make Content Appear Behind the Navigation Bar
                    |View.SYSTEM_UI_FLAG_FULLSCREEN  // hide status bar
                    |View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        }
    }

可以关闭。我将本教程用于我的 S8

How To Enable Full Screen Apps on Galaxy S8/S8+

要启用新的 Samsung Galaxy S8 和 LG G6 全屏支持,请添加到 <application> 元素下的 AndroidManifest.xml:

<meta-data android:name="android.max_aspect" android:value="2.1" />

其中 2.1 的值是纵横比 18.5:9(默认情况下,您的应用程序默认最大纵横比为 16:9 - 1.86)。更多信息见:Android Blog.

或者,您可以为 Application 或 Activity 设置以下属性:

android:resizeableActivity="true"

因为文档指出 (link):

You do not need to set a maximum aspect ratio if an activity's android:resizeableActivity attribute is set to true. If your app targets API level 24 or higher, this attribute defaults to true.