Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: (status-bar) Setting background color in Android 15 doesn't work #2341

@wm-eisos

Description

@wm-eisos

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.

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; 
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions