无法获得科尔多瓦 - 插件,状态栏设置颜色在Android [英] Can't get cordova-plugin-statusbar to set color on Android

查看:262
本文介绍了无法获得科尔多瓦 - 插件,状态栏设置颜色在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是类似<一个href=\"http://stackoverflow.com/questions/31429522/cant-set-color-of-statusbar-with-cordova-plugin-statusbar\">this 之一,但是我尝试了一切,仍然不能得到科尔多瓦 - 插件,状态栏工作

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

我使用的PhoneGap构建创建的PhoneGap /科尔多瓦应用程序。在 config.xml中我已经包含插件像这样:

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" />

然后我有一些JavaScript来设置状态栏的颜色:

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

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

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

不过,无论我做什么,我不能让状态栏来改变电话上的颜色。 PhoneGap的是使用科尔多瓦版本5.2.0和我的手机运行的是Android 5.1.1。

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.

推荐答案

添加该插件。运行shell命令:

Add the plugin. Run shell command:

$ cordova plugin add cordova-plugin-statusbar

编辑你的config.xml:

Edit your config.xml:

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

#BE1912是默认的颜色(在应用程序启动)。搜索结果
在运行时更改您的Java脚本code:

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

Change in run time from your java script code:

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

这篇关于无法获得科尔多瓦 - 插件,状态栏设置颜色在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆