33import android .app .Activity ;
44import android .app .Dialog ;
55import android .os .Build ;
6+ import android .view .WindowManager ;
67
78import java .lang .ref .WeakReference ;
89
@@ -21,7 +22,7 @@ public class SplashScreen {
2122 /**
2223 * 打开启动屏
2324 */
24- public static void show (final Activity activity , final int themeResId ) {
25+ public static void show (final Activity activity , final int themeResId , final boolean fullScreen ) {
2526 if (activity == null ) return ;
2627 mActivity = new WeakReference <Activity >(activity );
2728 activity .runOnUiThread (new Runnable () {
@@ -31,7 +32,9 @@ public void run() {
3132 mSplashDialog = new Dialog (activity , themeResId );
3233 mSplashDialog .setContentView (R .layout .launch_screen );
3334 mSplashDialog .setCancelable (false );
34-
35+ if (fullScreen ) {
36+ setActivityAndroidP (mSplashDialog );
37+ }
3538 if (!mSplashDialog .isShowing ()) {
3639 mSplashDialog .show ();
3740 }
@@ -46,7 +49,7 @@ public void run() {
4649 public static void show (final Activity activity , final boolean fullScreen ) {
4750 int resourceId = fullScreen ? R .style .SplashScreen_Fullscreen : R .style .SplashScreen_SplashTheme ;
4851
49- show (activity , resourceId );
52+ show (activity , resourceId , fullScreen );
5053 }
5154
5255 /**
@@ -89,4 +92,16 @@ public void run() {
8992 }
9093 });
9194 }
95+
96+ private static void setActivityAndroidP (Dialog dialog ) {
97+ //设置全屏展示
98+ if (Build .VERSION .SDK_INT >= 28 ) {
99+ if (dialog != null && dialog .getWindow () != null ) {
100+ dialog .getWindow ().addFlags (WindowManager .LayoutParams .FLAG_LAYOUT_NO_LIMITS );//全屏显示
101+ WindowManager .LayoutParams lp = dialog .getWindow ().getAttributes ();
102+ lp .layoutInDisplayCutoutMode = WindowManager .LayoutParams .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES ;
103+ dialog .getWindow ().setAttributes (lp );
104+ }
105+ }
106+ }
92107}
0 commit comments