简体   繁体   English

无法使用cordova-plugin-statusbar设置状态栏的颜色

[英]Can't set color of statusbar with cordova-plugin-statusbar

I'm trying to change the color of the native status bar in an ionic app, but I can't get it to work. 我试图在离子应用程序中更改本机状态栏的颜色,但我无法让它工作。 I've installed cordova-plugin-statusbar, and it installs fine. 我已经安装了cordova-plugin-statusbar,安装得很好。 The following code works perfectly: 以下代码完美运行:

if (StatusBar) {
    StatusBar.hide();
}

But trying to use any other of the available functions, for example: 但是尝试使用任何其他可用功能,例如:

if (StatusBar) {
    StatusBar.backgroundColorByHex('#RRGGBB');
}

doesn't work, the just app uses the standard statusbar. 不起作用,只是应用程序使用标准状态栏。

I've also added <preference name="StatusBarOverlaysWebView" value="true" /> to config.xml, as well as setting it programmatically at runtime. 我还在config.xml中添加了<preference name="StatusBarOverlaysWebView" value="true" /> ,并在运行时以编程方式设置它。

Cordova is version 5.1.1, Ionic is version 1.5.5 and I'm using Android 21 for testing. Cordova版本为5.1.1,Ionic版本为1.5.5,我使用的是Android 21进行测试。 Has anyone experienced the same problem or know how to fix it? 有没有人遇到同样的问题或知道如何解决它?

See me original solution at Can't get cordova-plugin-statusbar to set color on Android 请参阅我在原始解决方案中无法获取cordova-plugin-statusbar以在Android上设置颜色

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

Could you try removing the status bar plugin and reinstalling like so: 您可以尝试删除状态栏插件并重新安装,如下所示:

ionic plugin rm org.apache.cordova.statusbar
ionic plugin add https://github.com/apache/cordova-plugin-statusbar.git

The same has been reported at the ionic issue tracker 离子问题跟踪器也报道了相同的情况

Gil's solution doesn't work for me (I've a Samsung Galaxy S7 Edge). Gil的解决方案对我不起作用(我是三星Galaxy S7 Edge)。

onDeviceReady: function () {
    app.receivedEvent('deviceready');
    console.log(StatusBar);
    if (window.cordova && StatusBar) {
        StatusBar.backgroundColorByHexString('#BE1912');
    }
},

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

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