Benjamin
Benjamin

Reputation: 3950

Can't get cordova-plugin-statusbar to set color on Android

This question is similar to this one however I've tried everything and still can't get cordova-plugin-statusbar to work.

I'm using PhoneGap Build to create a PhoneGap / Cordova app. In config.xml I have the plugin included like so:

<gap:plugin name="cordova-plugin-statusbar" source="npm" />

And then I have some JavaScript to set the status bar color:

document.addEventListener('deviceready', SetStatusBarColor, false);

function SetStatusBarColor() {
  if (StatusBar) {
    StatusBar.backgroundColorByHexString('#4CAF50');
  }
}

However, no matter what I do, I can't get the status bar to change color on the phone. PhoneGap is using Cordova version 5.2.0 and my phone has Android 5.1.1.

Upvotes: 2

Views: 1699

Answers (1)

Gil Epshtain
Gil Epshtain

Reputation: 9801

Add the plugin. Run shell command:

$ cordova plugin add cordova-plugin-statusbar

Edit your config.xml:

<preference name="StatusBarOverlaysWebView" value="true" />
<preference name="StatusBarBackgroundColor" value="#BE1912" />

'#BE1912' is the default color (on app starts).

Change in run time from your java script code:

if (window.cordova && StatusBar)
{
    StatusBar.backgroundColorByHexString('#BE1912');
}

Upvotes: 4

Related Questions