3

I'm trying to change the color of the status bar to match the rest of the Page background-color and it seems to be not working.

Below is what my home.css looks like

Page {
    background-color: #5497CB;
    color:#ecf0f1;
}

Here is what my home.js looks like

var frameModule = require("ui/frame");

exports.loaded = function(args) {

    var page = args.object;
    var iosFrame = frameModule.topmost().ios;
    if (iosFrame) {
        iosFrame.navBarVisibility = 'never';
    }
};

And lastly here is what my home.xml

<Page loaded="loaded">
    <StackLayout orientation="vertical">
        <TextField id="email_address" text="{{ email }}" hint="Email Address" keyboardType="email" />
        <TextField secure="true" text="{{ password }}" hint="Password" />

        <Button text="Sign in" tap="signIn"/>
        <Button text="Sign up for Groceries" cssClass="link" tap="register"/>
    </StackLayout>
</Page>

As you can see nothing over complicated, just trying to get the status bar color to have a white font and same background color!

Any pointers?

Example of what it looks like now.

BaconJuice
  • 3,739
  • 13
  • 56
  • 88
  • This will be part of NativeScript 1.5.0. Until the release of this version, you can keep up with the discussion for this issue [here](https://github.com/NativeScript/NativeScript/issues/767). – Neli Chakarova Oct 21 '15 at 05:37
  • @NeliChakarova I was trying to follow this link http://developer.telerik.com/featured/customizing-ios-navigation-bar-status-bar-nativescript/ but that's good to know it's coming out in 1.5! – BaconJuice Oct 21 '15 at 12:13
  • I'm trying to set the Page background color and the status bar is not inheriting the color. I set the Page.backgroundSpanUnderStatusBarProperty to true and nothing happens. Still getting a grey status bar (I'm trying to set it red). Am I doing something wrong? – Andrey Luiz Jan 10 '16 at 15:44

6 Answers6

3

You're not using an action bar, so you need to set the backgroundSpanUnderStatusBar on the Page element to true.

<page backgroundSpanUnderStatusBar="true">

The text will still be black, but you can change that by changing the status bar to light for the whole application.

You can use the StatusBar Plugin for more control over the status bar in NativeScript.

Burke Holland
  • 2,325
  • 1
  • 22
  • 33
1

The Status Bar (time, battery indicator) inherits its background color from the Navigation Bar (back, page title, etc). But if you hide the Navigation Bar the Status Bar inherits the color from the Window background color instead. So if you want to change the color of the Status Bar with the Navigation Bar hidden you have to set the Window background color.

Here's an example of hiding the Nav bar and setting the status bar background to a gray-ish color.

var iosFrame = frameModule.topmost().ios;
if (iosFrame) {
    iosFrame.navBarVisibility = 'never';
    iosFrame.controller.view.window.backgroundColor = UIColor.colorWithRedGreenBlueAlpha(0.945, 0.953, 0.953, 1);
}

(colorWithRedGreenBlueAlpha wants a number between 0 and 1 where 1 is the same as 255 in a rgb(255, 255, 255) pattern. So basically divide with 255)

Emil Oberg
  • 4,006
  • 18
  • 30
1

This only works for android.

You can change the primary and primaryDark colors:

<style name="AppThemeBase" parent="Theme.AppCompat.Light.NoActionBar">
  <item name="toolbarStyle">@style/NativeScriptToolbarStyle</item>
  <item name="colorPrimary">@color/ns_primary</item>          <- Here
  <item name="colorPrimaryDark">@color/ns_primaryDark</item>  <- And here
  <item name="colorAccent">@color/ns_accent</item>
</style>

This answer solved my problems.

Community
  • 1
  • 1
Andrey Luiz
  • 461
  • 9
  • 25
1

To change the Background Color for Android use:

import { Page, Color } from "tns-core-modules/ui/page/page";

@Component({...}) 
export class YourAnyComponent {
    public constructor(private page: Page) {}
    ngOnInit() {
       this.page.androidStatusBarBackground = new Color("#0077cc");
    }
}
Daniel Ehrhardt
  • 908
  • 7
  • 16
0
import { Page } from "ui/page";

@Component({...}) 
export class YourAnyComponent {
    public constructor(private page: Page) {}
    ngOnInit() {
        this.page.backgroundColor = '#2c303a';
        this.page.backgroundSpanUnderStatusBar = true;
        this.page.actionBarHidden = false; // if you want to show only statusbar or - true if you want to show both stutus bar and action bar
    }
}
Ihor Khomiak
  • 1,151
  • 11
  • 17
0

For Android, It's as simple as that. Just copy paste below lines in E:\projects\appname\app\App_Resources\Android\src\main\res\values\styles.xml

<item name="android:statusBarColor">@color/ns_primaryDark</item>
<item name="android:windowLightStatusBar">true</item>

put it under any theme you want, Usually I put this under AppThemeBase

Vikas Acharya
  • 3,550
  • 4
  • 19
  • 52