johuether commented on issue #1949:
URL:
https://github.com/apache/cordova-android/issues/1949#issuecomment-5206498790
---
Hi! I'm also affected by this and think it's a real bug/problem. I've
narrowed it down a bit further on the native side.
My setup: an app that targets Android 17 (API 36) and uses edge-to-edge
mode. Looks good on newer Android versions, but on older devices the status bar
is solid black and can't be made transparent through the plugin
(`window.statusbar.setBackgroundColor(...)` with a transparent/alpha color).
### What I found
Even when the correct ARGB value actually reaches the native side,
`SystemBarPlugin.updateStatusBar()` unconditionally paints the color onto the
in-app `statusBar` overlay:
```java
View statusBar = getStatusBarView(webView);
if (statusBar != null) {
statusBar.setBackgroundColor(bgColor);
}
```
That overlay approach is what's needed on API 35+ (Android 15+,
`VANILLA_ICE_CREAM`), where the platform ignores
`window.setStatusBarColor(...)` and forces the bar transparent. On older
devices, though, `setStatusBarColor(...)` works at the window level - but only
if the window is allowed to draw its own system bar background. Without that, a
transparent request just gets ignored and the bar falls back to the default
opaque/black decoration, which is exactly the black bar I'm seeing.
### Suggested fix
Branch on the build version: on API 35+ keep the overlay behavior, on older
devices set the color directly at the window level. Picking one path or the
other also avoids double-blending translucent colors.
```java
@SuppressWarnings("deprecation")
private void updateStatusBar(int bgColor) {
Window window = cordova.getActivity().getWindow();
// API 35+ ignores window.setStatusBarColor (the platform forces the
bar
// transparent), so paint via the in-app overlay there. On older
devices
// color the system bar directly at the window level. Using one or
the
// other (not both) also avoids double-blending translucent colors.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
View statusBar = getStatusBarView(webView);
if (statusBar != null) {
statusBar.setBackgroundColor(bgColor);
}
} else {
window.setStatusBarColor(bgColor);
}
// Automatically set the font and icon color of the system bars
based on background color.
boolean isStatusBarBackgroundColorLight;
if (bgColor == Color.TRANSPARENT) {
isStatusBarBackgroundColorLight = isColorLight(getUiModeColor());
} else {
isStatusBarBackgroundColorLight = isColorLight(bgColor);
}
WindowInsetsControllerCompat controllerCompat =
WindowCompat.getInsetsController(window, window.getDecorView());
controllerCompat.setAppearanceLightStatusBars(isStatusBarBackgroundColorLight);
}
```
With this the status bar becomes properly transparent on older devices in
edge-to-edge mode, and API 35+ keeps the current overlay behavior. Happy to
turn it into a PR if there's interest.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]