From 82fd5a095f6575615f3a271d57ec35cb26026fad Mon Sep 17 00:00:00 2001 From: SMH17 Date: Fri, 25 Jul 2025 03:06:34 +0200 Subject: [PATCH] Address the still unfixed issues related to setStatusBarColor and setNavigationBarColor warning targeting API level 35 and above. --- .../catalog/sidesheet/SideSheetMainDemoFragment.java | 5 ++++- .../android/material/bottomsheet/BottomSheetDialog.java | 8 +++++--- .../android/material/internal/EdgeToEdgeUtils.java | 9 ++++++--- .../google/android/material/sidesheet/SheetDialog.java | 7 +++++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/catalog/java/io/material/catalog/sidesheet/SideSheetMainDemoFragment.java b/catalog/java/io/material/catalog/sidesheet/SideSheetMainDemoFragment.java index 3e79773ef4e..3a3fbf04a3c 100644 --- a/catalog/java/io/material/catalog/sidesheet/SideSheetMainDemoFragment.java +++ b/catalog/java/io/material/catalog/sidesheet/SideSheetMainDemoFragment.java @@ -324,7 +324,10 @@ private void setUpModalSheet( context, androidx.appcompat.R.attr.isLightTheme, true); Window window = sheetDialog.getWindow(); sheetDialog.setFitsSystemWindows(!edgeToEdgeEnabled); - window.setNavigationBarColor(Color.TRANSPARENT); + if (VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) { + // In API 35 the call to setNavigationBarColor is deprecated, doesn't affect gesture navigation and nav bar is set to match window background. + window.setNavigationBarColor(Color.TRANSPARENT); + } WindowCompat.getInsetsController(window, window.getDecorView()) .setAppearanceLightStatusBars(edgeToEdgeEnabled && isLightTheme); diff --git a/lib/java/com/google/android/material/bottomsheet/BottomSheetDialog.java b/lib/java/com/google/android/material/bottomsheet/BottomSheetDialog.java index a69485116bd..0915dd0407e 100644 --- a/lib/java/com/google/android/material/bottomsheet/BottomSheetDialog.java +++ b/lib/java/com/google/android/material/bottomsheet/BottomSheetDialog.java @@ -135,9 +135,11 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Window window = getWindow(); if (window != null) { - // The status bar should always be transparent because of the window animation. - window.setStatusBarColor(0); - + if (VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) { + // The status bar should always be transparent because of the window animation. + // Starting with API 35, the call to setStatusBarColor() is deprecated and no longer works, since the status bar is always transparent. + window.setStatusBarColor(0); + } window.addFlags(LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); if (VERSION.SDK_INT < VERSION_CODES.M) { // It can be transparent for API 23 and above because we will handle switching the status diff --git a/lib/java/com/google/android/material/internal/EdgeToEdgeUtils.java b/lib/java/com/google/android/material/internal/EdgeToEdgeUtils.java index 73a3c783503..b581f80068c 100644 --- a/lib/java/com/google/android/material/internal/EdgeToEdgeUtils.java +++ b/lib/java/com/google/android/material/internal/EdgeToEdgeUtils.java @@ -93,9 +93,12 @@ public static void applyEdgeToEdge( int statusBarColor = getStatusBarColor(window.getContext(), edgeToEdgeEnabled); int navigationBarColor = getNavigationBarColor(window.getContext(), edgeToEdgeEnabled); - - window.setStatusBarColor(statusBarColor); - window.setNavigationBarColor(navigationBarColor); + if (VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) { + // Starting with API 35, the call to setStatusBarColor() is deprecated and no longer works, since the status bar is always transparent. + window.setStatusBarColor(statusBarColor); + // In API 35 the call to setNavigationBarColor is deprecated, doesn't affect gesture navigation and nav bar is set to match window background. + window.setNavigationBarColor(navigationBarColor); + } setLightStatusBar( window, diff --git a/lib/java/com/google/android/material/sidesheet/SheetDialog.java b/lib/java/com/google/android/material/sidesheet/SheetDialog.java index a2a728c0f77..b9e4d4ec29c 100644 --- a/lib/java/com/google/android/material/sidesheet/SheetDialog.java +++ b/lib/java/com/google/android/material/sidesheet/SheetDialog.java @@ -100,8 +100,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Window window = getWindow(); if (window != null) { - // The status bar should always be transparent because of the window animation. - window.setStatusBarColor(0); + if (VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) { + // The status bar should always be transparent because of the window animation. + // Starting with API 35, the call to setStatusBarColor() is deprecated and no longer works, since the status bar is always transparent. + window.setStatusBarColor(0); + } window.addFlags(LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); if (VERSION.SDK_INT < VERSION_CODES.M) {