在Cordova中更改Android状态栏颜色

6
我想在Android中更改状态栏的颜色(我正在使用6.0进行测试)。我尝试了statusbar插件和所有我能找到的解决方案,但都没有起作用。
这是我的config.xml <widget>中包含的内容:
<preference name="StatusBarOverlaysWebView" value="true" />
<preference name="StatusBarBackgroundColor" value="#BE1912" />

我的 index.js 包含:

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

已按软件包名称和Github存储库添加插件。

目前为止没有任何效果...

提前感谢!:)

3个回答

6
状态栏插件将会工作。请从config.xml中删除这些行。
<preference name="StatusBarOverlaysWebView" value="true" />
<preference name="StatusBarBackgroundColor" value="#BE1912" />

StatusBar.backgroundColorByHexString('#3399FF'); 写入deviceready中,如下所示:

document.addEventListener('deviceready', function(){
StatusBar.backgroundColorByHexString('#3399FF');});

你是否写好了设备就绪的代码?把完整的 JS 文件给我看。 - Homen
你已经写了两个设备就绪函数,请删除你的所有代码。只编写我在答案中张贴的代码。你应该只编写一个设备就绪函数。 - Homen
仍然无法工作...我确定不是因为我的设备,因为它在其他应用程序中可以运行。这是我唯一的代码:document.addEventListener('deviceready', function(){ StatusBar.backgroundColorByHexString('#3399FF');}); - Voakie
请参考此链接 - https://dev59.com/4o3da4cB1Zd3GeqPuQkL - Krishna

4

我只是在config.xml文件中包含了以下偏好设置,现在它正常工作:

<preference name="StatusBarOverlaysWebView" value="true" />
<preference name="StatusBarBackgroundColor" value="#5b2e90" />
<preference name="StatusBarStyle" value="lightcontent" />

对我不起作用.. <widget ...><your code>...</widget> - Fipsi

1
请在index.html(应用程序的启动页面)中提及下面的代码。
注意:无需在整个Cordova应用程序中提及,只需在index.html(应用程序的启动页面)中提及即可。

<script type="text/javascript" charset="utf-8">
        $(document).ready(function () {
             document.addEventListener("deviceready", onDeviceReady, false); 


        });

        function onDeviceReady() {

            StatusBar.overlaysWebView(false);
            StatusBar.backgroundColorByHexString("#333"); // => #333333

             StatusBar.styleLightContent();
            console.log(statusbar);

        }
</script>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接