在离子2应用程序中更改iOS状态栏颜色 [英] Change iOS status bar color in ionic 2 app
问题描述
我正在关注离子2文档以设置iOS状态栏颜色,但它无法正常工作。状态栏文本是白色的,这意味着在我的白色背景上它是不可见的。
I am following the ionic 2 documentation for setting the iOS status bar color but it is not working. The status bar text is white which means on my white background it is invisible.
我在我的应用程序构造函数中放置的代码是:
The code I have put in my app constructor is:
StatusBar.overlaysWebView(true);
StatusBar.styleDefault();
我使用以下方式导入StatusBar:
I have imported StatusBar using:
import {StatusBar} from 'ionic-native';
我还检查过安装了cordova statusbar插件。
I have also checked that the cordova statusbar plugin is installed.
推荐答案
您可以尝试在config.xml中添加此项,并使用您要设置的颜色的十六进制值:
You can try like this add this in the config.xml, with the hex value of the color you want to set:
<preference name="StatusBarOverlaysWebView" value="false" />
<preference name="StatusBarBackgroundColor" value="#000000" />
对于ngCordova或离子原生,你可以使用
For ngCordova or ionic-native you can use
$cordovaStatusbar.styleColor('black');
$cordovaStatusbar.styleHex('#000');
或者你检查在状态栏cordova插件github页面上有一些方法可以更改状态栏的颜色: https:// github.com/apache/cordova-plugin-statusbar
对于Android:
if (cordova.platformId == 'android') {
StatusBar.backgroundColorByHexString("#333");
}
适用于iOS
在iOS 7上,当您将StatusBar.statusBarOverlaysWebView设置为false时,您可以按颜色名称设置状态栏的背景颜色。
On iOS 7, when you set StatusBar.statusBarOverlaysWebView to false, you can set the background color of the statusbar by color name.
StatusBar.backgroundColorByName("red");
支持的颜色名称为:
black, darkGray, lightGray, white, gray, red, green, blue, cyan, yellow, magenta, orange, purple, brown
或
按十六进制字符串设置状态栏的背景颜色。
Or
Sets the background color of the statusbar by a hex string.
StatusBar.backgroundColorByHexString("#C0C0C0");
也支持CSS速记属性。
CSS shorthand properties are also supported.
StatusBar.backgroundColorByHexString("#333"); // => #333333
StatusBar.backgroundColorByHexString("#FAB"); // => #FFAABB
On iOS 7, when you set StatusBar.statusBarOverlaysWebView to false, you can set the background color of the statusbar by a hex string (#RRGGBB).
在WP7和WP8上,您还可以将值指定为#AARRGGBB,其中AA是alpha值
On WP7 and WP8 you can also specify values as #AARRGGBB, where AA is an alpha value
这篇关于在离子2应用程序中更改iOS状态栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!