@@ -35,56 +35,43 @@ public FrameLayout getWrapperView(@ColorInt int defaultColor) {
3535 Insets systemBarInsets = insets .getInsets (WindowInsetsCompat .Type .systemBars ());
3636 mSystemBarBackgroundDrawable .setSystemBarPaddings (systemBarInsets .top , systemBarInsets .bottom );
3737 v .setPadding (0 , systemBarInsets .top , 0 , systemBarInsets .bottom );
38- v .invalidate ();
39- return insets ;
38+ return WindowInsetsCompat .CONSUMED ;
4039 });
4140
41+ // This is required to make system bars transparent
4242 ViewCompat .setOnApplyWindowInsetsListener (mActivity .getWindow ().getDecorView (), (v , insets ) -> insets );
4343
4444 return rootView ;
4545 }
4646
4747 public void setStatusBarColor (@ ColorInt int color ) {
4848 if (Build .VERSION .SDK_INT <= Build .VERSION_CODES .UPSIDE_DOWN_CAKE ) {
49+ // Call the old API for compatibility with older SDKs, in case edge to edge cannot be enabled
4950 mActivity .getWindow ().setStatusBarColor (color );
5051 }
5152 mSystemBarBackgroundDrawable .setStatusBarColor (color );
52- if (shouldUseDarkIconsOnBackground (color )) {
53- addSystemUiVisibilityFlag (mActivity , View .SYSTEM_UI_FLAG_LIGHT_STATUS_BAR );
5453 WindowInsetsControllerCompat windowInsetsController =
5554 WindowCompat .getInsetsController (mActivity .getWindow (), mActivity .getWindow ().getDecorView ());
5655 if (windowInsetsController != null ) {
57- windowInsetsController . setAppearanceLightStatusBars ( true );
58- }
56+ boolean shouldUseDarkIcons = shouldUseDarkIconsOnBackground ( color );
57+ windowInsetsController . setAppearanceLightStatusBars ( shouldUseDarkIcons );
5958 }
6059 }
6160
6261 public void setNavigationBarColor (@ ColorInt int color ) {
6362 if (Build .VERSION .SDK_INT <= Build .VERSION_CODES .UPSIDE_DOWN_CAKE ) {
63+ // Call the old API for compatibility with older SDKs, in case edge to edge cannot be enabled
6464 mActivity .getWindow ().setNavigationBarColor (color );
6565 }
6666 mSystemBarBackgroundDrawable .setNavigationBarColor (color );
67- if (shouldUseDarkIconsOnBackground (color )) {
68- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
69- addSystemUiVisibilityFlag (mActivity , View .SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR );
70- }
7167 WindowInsetsControllerCompat windowInsetsController =
7268 WindowCompat .getInsetsController (mActivity .getWindow (), mActivity .getWindow ().getDecorView ());
7369 if (windowInsetsController != null ) {
74- windowInsetsController . setAppearanceLightNavigationBars ( true );
75- }
70+ boolean shouldUseDarkIcons = shouldUseDarkIconsOnBackground ( color );
71+ windowInsetsController . setAppearanceLightNavigationBars ( shouldUseDarkIcons );
7672 }
7773 }
7874
79- private static void addSystemUiVisibilityFlag (Activity activity , int flag ) {
80- if (Build .VERSION .SDK_INT > Build .VERSION_CODES .UPSIDE_DOWN_CAKE ) return ;
81-
82- View root = activity .getWindow ().getDecorView ().getRootView ();
83- int visibility = root .getSystemUiVisibility ();
84- visibility |= flag ;
85- root .setSystemUiVisibility (visibility );
86- }
87-
8875 /**
8976 * Determines whether to use dark icons on a background with given color by comparing the
9077 * contrast ratio (https://www.w3.org/TR/WCAG20/#contrast-ratiodef) to a threshold.
0 commit comments