Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions packages/android-edge-to-edge-support/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ Otherwise, the web view will be resized to fit the screen, which may cause issue
<docgen-config>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

| Prop | Type | Description | Since |
| --------------------- | ------------------- | ------------------------------------------------------------------------------------------ | ----- |
| **`backgroundColor`** | <code>string</code> | The hexadecimal color to set as the background color of the status bar and navigation bar. | 7.1.0 |
| Prop | Type | Description | Since |
| ------------------------------ | ------------------- | ------------------------------------------------------------------------------------------ | ----- |
| **`backgroundColor`** | <code>string</code> | The hexadecimal color to set as the background color of the status bar and navigation bar. | 7.1.0 |
| **`statusBarBackgroundColor`** | <code>string</code> | The hexadecimal color to set as the background color of the status bar and navigation bar. | 7.1.0 |

### Examples

Expand All @@ -52,7 +53,8 @@ In `capacitor.config.json`:
{
"plugins": {
"EdgeToEdge": {
"backgroundColor": "#ffffff"
"backgroundColor": "#ffffff",
"statusBarBackgroundColor": "#ffffff"
}
}
}
Expand All @@ -69,6 +71,7 @@ const config: CapacitorConfig = {
plugins: {
EdgeToEdge: {
backgroundColor: "#ffffff",
statusBarBackgroundColor: "#ffffff",
},
},
};
Expand Down Expand Up @@ -113,6 +116,7 @@ const setBackgroundColor = async () => {
* [`disable()`](#disable)
* [`getInsets()`](#getinsets)
* [`setBackgroundColor(...)`](#setbackgroundcolor)
* [`setStatusBarBackgroundColor(...)`](#setstatusbarbackgroundcolor)
* [Interfaces](#interfaces)

</docgen-index>
Expand Down Expand Up @@ -173,7 +177,26 @@ Only available on Android.
setBackgroundColor(options: SetBackgroundColorOptions) => Promise<void>
```

Set the background color of the status bar and navigation bar.
Set the background color of the navigation bar.

Only available on Android.

| Param | Type |
| ------------- | ------------------------------------------------------------------------------- |
| **`options`** | <code><a href="#setbackgroundcoloroptions">SetBackgroundColorOptions</a></code> |

**Since:** 7.0.0

--------------------


### setStatusBarBackgroundColor(...)

```typescript
setStatusBarBackgroundColor(options: SetBackgroundColorOptions) => Promise<void>
```

Set the background color of the status bar.

Only available on Android.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package io.capawesome.capacitorjs.plugins.androidedgetoedgesupport;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
Expand All @@ -18,12 +22,15 @@ public class EdgeToEdge {
@NonNull
private final EdgeToEdgePlugin plugin;

private View overlayView;

public EdgeToEdge(@NonNull EdgeToEdgePlugin plugin, @NonNull EdgeToEdgeConfig config) {
this.config = config;
this.plugin = plugin;
// Apply insets to disable the edge-to-edge feature
setBackgroundColor(config.getBackgroundColor());
applyInsets();
setStatusBarBackgroundColor(config.getStatusBarBackgroundColor());
}

public void enable() {
Expand All @@ -43,6 +50,10 @@ public void setBackgroundColor(String color) {
setBackgroundColor(Color.parseColor(color));
}

public void setStatusBarBackgroundColor(String color) {
setStatusBarBackgroundColor(Color.parseColor(color));
}

private void applyInsets() {
View view = plugin.getBridge().getWebView();
// Get parent view
Expand Down Expand Up @@ -102,6 +113,11 @@ private void removeInsets() {
mlp.rightMargin = 0;
mlp.bottomMargin = 0;
view.setLayoutParams(mlp);
if (overlayView != null) {
ViewGroup parentLayout = (ViewGroup) overlayView.getParent();
parentLayout.removeView(overlayView);
overlayView = null;
}
// Reset listener
ViewCompat.setOnApplyWindowInsetsListener(view, null);
}
Expand All @@ -113,4 +129,33 @@ private void setBackgroundColor(int color) {
// Set background color
parent.setBackgroundColor(color);
}

private void setStatusBarBackgroundColor(int color) {
View view = plugin.getBridge().getWebView();
Activity activity = plugin.getBridge().getActivity();
// Create new view
View overlay = new View(activity);
WindowInsetsCompat currentInsets = ViewCompat.getRootWindowInsets(view);
if (currentInsets != null) {
int statusBarHeight = currentInsets.getInsets(
WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout()
).top;
overlay.setLayoutParams(new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
statusBarHeight
));
overlay.setBackgroundColor(color);
// Get root view bridge activity
ViewGroup rootView = (ViewGroup) activity.getWindow().getDecorView();

// Remove previous overlay if exist
if (overlayView != null) {
rootView.removeView(overlayView);
}
// Set reference overlay view
overlayView = overlay;
// Add overlay view
rootView.addView(overlay);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public class EdgeToEdgeConfig {

private int backgroundColor = Color.WHITE;
private int statusBarBackgroundColor = Color.WHITE;

public int getBackgroundColor() {
return this.backgroundColor;
Expand All @@ -13,4 +14,12 @@ public int getBackgroundColor() {
public void setBackgroundColor(int backgroundColor) {
this.backgroundColor = backgroundColor;
}

public int getStatusBarBackgroundColor() {
return this.statusBarBackgroundColor;
}

public void setStatusBarBackgroundColor(int statusBarBackgroundColor) {
this.statusBarBackgroundColor = backgroundColor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,36 @@ public void setBackgroundColor(PluginCall call) {
});
}

@PluginMethod
public void setStatusBarBackgroundColor(PluginCall call) {
String color = call.getString("color");
if (color == null) {
call.reject(ERROR_COLOR_MISSING);
return;
}
getActivity()
.runOnUiThread(() -> {
try {
implementation.setStatusBarBackgroundColor(color);
call.resolve();
} catch (Exception exception) {
call.reject(exception.getMessage());
}
});
}

private EdgeToEdgeConfig getEdgeToEdgeConfig() {
EdgeToEdgeConfig config = new EdgeToEdgeConfig();

try {
String backgroundColor = getConfig().getString("backgroundColor");
String statusBarBackgroundColor = getConfig().getString("statusBarBackgroundColor");
if (backgroundColor != null) {
config.setBackgroundColor(Color.parseColor(backgroundColor));
}
if (statusBarBackgroundColor != null) {
config.setStatusBarBackgroundColor(Color.parseColor(statusBarBackgroundColor));
}
} catch (Exception exception) {
Logger.error(TAG, "Set config failed.", exception);
}
Expand Down
17 changes: 16 additions & 1 deletion packages/android-edge-to-edge-support/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ declare module '@capacitor/cli' {
* @example "#ffffff"
*/
backgroundColor?: string;
/**
* The hexadecimal color to set as the background color of the status bar and navigation bar.
*
* @since 7.1.0
* @example "#ffffff"
*/
statusBarBackgroundColor?: string;
};
}
}
Expand Down Expand Up @@ -40,13 +47,21 @@ export interface EdgeToEdgePlugin {
*/
getInsets(): Promise<GetInsetsResult>;
/**
* Set the background color of the status bar and navigation bar.
* Set the background color of the navigation bar.
*
* Only available on Android.
*
* @since 7.0.0
*/
setBackgroundColor(options: SetBackgroundColorOptions): Promise<void>;
Copy link
Copy Markdown

@mariomurrent-softwaresolutions mariomurrent-softwaresolutions Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May this methods needs to be renamed as well to setNavigationBarBackgroundColor. And accordingly to all the other methods and properties as well.

As also stated in one comment

/**
* Set the background color of the status bar.
*
* Only available on Android.
*
* @since 7.0.0
*/
setStatusBarBackgroundColor(options: SetBackgroundColorOptions): Promise<void>;
}

/**
Expand Down
Loading