简体   繁体   English

无法在Android上获取cordova-plugin-statusbar设置颜色

[英]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. 这个问题与类似,但是我已经尝试了一切,但仍然无法使cordova-plugin-statusbar正常工作。

I'm using PhoneGap Build to create a PhoneGap / Cordova app. 我正在使用PhoneGap Build创建一个PhoneGap / Cordova应用程序。 In config.xml I have the plugin included like so: config.xml我包含了这样的插件:

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

And then I have some JavaScript to set the status bar color: 然后我有一些JavaScript来设置状态栏的颜色:

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. PhoneGap使用的是Cordova版本5.2.0,并且我的手机具有Android 5.1.1。

Add the plugin. 添加插件。 Run shell command: 运行shell命令:

$ cordova plugin add cordova-plugin-statusbar

Edit your config.xml: 编辑您的config.xml:

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

'#BE1912' is the default color (on app starts). “#BE1912”是默认颜色(在应用启动时)。

Change in run time from your java script code: 通过Java脚本代码更改运行时间:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM