Android P+ 異形屏全屏
於 2020年7月14日 (二) 06:27 由 Silica(留言 | 貢獻) 所做的修訂 (创建页面,内容为“Category:Android 2020-07-14 14:25 == Java == <pre> @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /…”)
2020-07-14 14:25
Java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 延伸显示区域到刘海 if (Build.VERSION.SDK_INT >= 28) { WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; getWindow().setAttributes(lp); // 设置页面全屏显示 final View decorView = getWindow().getDecorView(); decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); } setContentView(R.layout...); }
XML
<style name="AppTheme" parent="..."> <item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="o_mr1">shortEdges</item> </style>