Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Android Statusbar color In Cordova

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! :)

like image 206
Voakie Avatar asked Jul 03 '16 10:07

Voakie


3 Answers

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');});
like image 150
Homen Avatar answered Sep 21 '22 13:09

Homen


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" />
like image 24
Jordan Ferr Avatar answered Sep 19 '22 13:09

Jordan Ferr


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>
like image 43
Narendra Reddy Avatar answered Sep 18 '22 13:09

Narendra Reddy