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

我只是一个虾纸丫 提交于 2019-12-22 19:24:27

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/32922115/cant-get-cordova-plugin-statusbar-to-set-color-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!