This is an automated email from the ASF dual-hosted git repository.
erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-android.git
The following commit(s) were added to refs/heads/master by this push:
new dd3fd357 fix(statusbar): Properly handle CSS colours (#1955)
dd3fd357 is described below
commit dd3fd3571ecd41e7b81cfb6e05b626413655c732
Author: Darryl Pogue <[email protected]>
AuthorDate: Mon Jun 22 21:52:12 2026 -0700
fix(statusbar): Properly handle CSS colours (#1955)
---
cordova-js-src/plugin/android/statusbar.js | 33 +++++++++++-----------
.../src/org/apache/cordova/SystemBarPlugin.java | 18 ++++++------
2 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/cordova-js-src/plugin/android/statusbar.js
b/cordova-js-src/plugin/android/statusbar.js
index a4baeabf..131c0139 100644
--- a/cordova-js-src/plugin/android/statusbar.js
+++ b/cordova-js-src/plugin/android/statusbar.js
@@ -60,28 +60,29 @@ Object.defineProperty(statusBar, 'setBackgroundColor', {
statusBarScript.style.color = value;
var rgbStr =
window.getComputedStyle(statusBarScript).getPropertyValue('color');
- if (!rgbStr.match(/^rgb/)) { return; }
-
- var rgbVals = rgbStr.match(/\d+/g).map(function (v) { return
parseInt(v, 10); });
+ if (!rgbStr.match(/^rgb/)) {
+ return;
+ }
+ var rgbVals = rgbStr.match(/[\d.]+/g).map(function (v, i) { return (i
< 3) ? parseInt(v, 10) : parseFloat(v); });
if (rgbVals.length < 3) {
return;
- } else if (rgbVals.length === 3) {
- rgbVals = [255].concat(rgbVals);
}
- // TODO: Use `padStart(2, '0')` once SDK 24 is dropped.
- const padRgb = (val) => {
- const hex = val.toString(16);
- return hex.length === 1 ? '0' + hex : hex;
- };
- const a = padRgb(rgbVals[0]);
- const r = padRgb(rgbVals[1]);
- const g = padRgb(rgbVals[2]);
- const b = padRgb(rgbVals[3]);
- const hexStr = '#' + a + r + g + b;
-
if (window.StatusBar) {
+ // try to let the StatusBar plugin handle it
+ // TODO: Use `padStart(2, '0')` once SDK 24 is dropped.
+ const padRgb = (val) => {
+ const hex = val.toString(16);
+ return hex.length === 1 ? '0' + hex : hex;
+ };
+
+ const r = padRgb(rgbVals[0]);
+ const g = padRgb(rgbVals[1]);
+ const b = padRgb(rgbVals[2]);
+ const a = padRgb(255 * (rgbVals[3] !== undefined ? rgbVals[3] :
1.0));
+
+ const hexStr = '#' + a + r + g + b;
window.StatusBar.backgroundColorByHexString(hexStr);
} else {
exec(null, null, 'SystemBarPlugin', 'setStatusBarBackgroundColor',
rgbVals);
diff --git a/framework/src/org/apache/cordova/SystemBarPlugin.java
b/framework/src/org/apache/cordova/SystemBarPlugin.java
index 4967b121..c03721f0 100644
--- a/framework/src/org/apache/cordova/SystemBarPlugin.java
+++ b/framework/src/org/apache/cordova/SystemBarPlugin.java
@@ -121,19 +121,17 @@ public class SystemBarPlugin extends CordovaPlugin {
* If the supplied ARGB is invalid or fails to parse, it will silently
ignore
* the change request.
*
- * @param argbVals {A, R, G, B}
+ * @param argbVals {R, G, B, A}
*/
private void setStatusBarBackgroundColor(JSONArray argbVals) {
try {
- int a = argbVals.getInt(0);
- int r = argbVals.getInt(1);
- int g = argbVals.getInt(2);
- int b = argbVals.getInt(3);
- overrideStatusBarBackgroundColor =
parseColorFromString(String.format("#%02X%02X%02X%02X", a, r, g, b));
-
- if (overrideStatusBarBackgroundColor != null) {
- updateStatusBar(overrideStatusBarBackgroundColor);
- }
+ int r = argbVals.getInt(0);
+ int g = argbVals.getInt(1);
+ int b = argbVals.getInt(2);
+ int a = Math.round(255 * (float)argbVals.optDouble(3, 1.0));
+
+ overrideStatusBarBackgroundColor = Color.argb(a, r, g, b);
+ updateStatusBar(overrideStatusBarBackgroundColor);
} catch (JSONException e) {
// Silently skip
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]