Skip to content

Commit 82fd5a0

Browse files
committed
Address the still unfixed issues related to setStatusBarColor and setNavigationBarColor warning targeting API level 35 and above.
1 parent 42e0322 commit 82fd5a0

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

catalog/java/io/material/catalog/sidesheet/SideSheetMainDemoFragment.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ private void setUpModalSheet(
324324
context, androidx.appcompat.R.attr.isLightTheme, true);
325325
Window window = sheetDialog.getWindow();
326326
sheetDialog.setFitsSystemWindows(!edgeToEdgeEnabled);
327-
window.setNavigationBarColor(Color.TRANSPARENT);
327+
if (VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
328+
// In API 35 the call to setNavigationBarColor is deprecated, doesn't affect gesture navigation and nav bar is set to match window background.
329+
window.setNavigationBarColor(Color.TRANSPARENT);
330+
}
328331
WindowCompat.getInsetsController(window, window.getDecorView())
329332
.setAppearanceLightStatusBars(edgeToEdgeEnabled && isLightTheme);
330333

lib/java/com/google/android/material/bottomsheet/BottomSheetDialog.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,11 @@ protected void onCreate(Bundle savedInstanceState) {
135135
super.onCreate(savedInstanceState);
136136
Window window = getWindow();
137137
if (window != null) {
138-
// The status bar should always be transparent because of the window animation.
139-
window.setStatusBarColor(0);
140-
138+
if (VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
139+
// The status bar should always be transparent because of the window animation.
140+
// Starting with API 35, the call to setStatusBarColor() is deprecated and no longer works, since the status bar is always transparent.
141+
window.setStatusBarColor(0);
142+
}
141143
window.addFlags(LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
142144
if (VERSION.SDK_INT < VERSION_CODES.M) {
143145
// It can be transparent for API 23 and above because we will handle switching the status

lib/java/com/google/android/material/internal/EdgeToEdgeUtils.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ public static void applyEdgeToEdge(
9393

9494
int statusBarColor = getStatusBarColor(window.getContext(), edgeToEdgeEnabled);
9595
int navigationBarColor = getNavigationBarColor(window.getContext(), edgeToEdgeEnabled);
96-
97-
window.setStatusBarColor(statusBarColor);
98-
window.setNavigationBarColor(navigationBarColor);
96+
if (VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
97+
// Starting with API 35, the call to setStatusBarColor() is deprecated and no longer works, since the status bar is always transparent.
98+
window.setStatusBarColor(statusBarColor);
99+
// In API 35 the call to setNavigationBarColor is deprecated, doesn't affect gesture navigation and nav bar is set to match window background.
100+
window.setNavigationBarColor(navigationBarColor);
101+
}
99102

100103
setLightStatusBar(
101104
window,

lib/java/com/google/android/material/sidesheet/SheetDialog.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
100100
super.onCreate(savedInstanceState);
101101
Window window = getWindow();
102102
if (window != null) {
103-
// The status bar should always be transparent because of the window animation.
104-
window.setStatusBarColor(0);
103+
if (VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
104+
// The status bar should always be transparent because of the window animation.
105+
// Starting with API 35, the call to setStatusBarColor() is deprecated and no longer works, since the status bar is always transparent.
106+
window.setStatusBarColor(0);
107+
}
105108

106109
window.addFlags(LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
107110
if (VERSION.SDK_INT < VERSION_CODES.M) {

0 commit comments

Comments
 (0)