-
Notifications
You must be signed in to change notification settings - Fork 656
Open
Labels
Description
Bug Report
Plugin(s)
@capacitor/status-bar 7.0.1
Capacitor Version
Latest Dependencies:
@capacitor/cli: 7.2.0
@capacitor/core: 7.2.0
@capacitor/android: 7.2.0
@capacitor/ios: 7.2.0
Installed Dependencies:
@capacitor/cli: 7.2.0
@capacitor/android: 7.2.0
@capacitor/core: 7.2.0
@capacitor/ios: 7.2.0
Platform(s)
Android 15
Current Behavior
Setting the backgroud color of the status bar in android 15 doesn't work anymore.
capacitor-plugins/status-bar/android/src/main/java/com/capacitorjs/plugins/statusbar/StatusBar.java
Lines 65 to 72 in 927f549
public void setBackgroundColor(int color) { | |
Window window = activity.getWindow(); | |
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | |
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
window.setStatusBarColor(color); | |
// update the local color field as well | |
currentStatusBarColor = color; | |
} |
Expected Behavior
The setting of the status bar background color works as expected on android 15
Code Reproduction
Other Technical Details
Additional Context
This can be solved using the following
public void setBackgroundColor(int color) {
Window window = activity.getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { // Android 15+
window.getDecorView().setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
WindowInsets.StatusBarInsets statusBarInsets = insets.getInsets(WindowInsets.Type.statusBars());
view.setBackgroundColor(color);
// Adjust padding to avoid overlap
view.setPadding(0, statusBarInsets.getTop(), 0, 0);
return insets;
}
});
} else {
// For Android 14 and below
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(color);
}
// update the local color field as well
currentStatusBarColor = color;
}
pkusnir, gniuslab, matigaleanodev, amaron09, SamTheWizard and 8 more