Change Android Statusbar color In Cordova

送分小仙女□ 提交于 2019-12-07 04:45:17

问题


I want to change the Status bar color in Android (I'm using 6.0 for testing). I tried the statusbar plugin and all the solutions I found for it but nothing worked.

This is included in my config.xml <widget>:

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

My index.js uncludes:

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

Added the plugin per package name and github repo.

Nothing worked so far...

Thanks in advance! :)


回答1:


Statusbar plugin will work.Remove these lines from config.xml

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

And write StatusBar.backgroundColorByHexString('#3399FF'); inside deviceready like following

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



回答2:


I just included the following preferences in config.xml and is working now:

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



回答3:


Mention the below code in index.html( app's starting page )
Note:- No need to mention in entire Cordova Application , Just mention in the index.html ( app's starting page )

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


来源:https://stackoverflow.com/questions/38168925/change-android-statusbar-color-in-cordova

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