Change iOS status bar color in ionic 2 app(在 ionic 2 应用程序中更改 iOS 状态栏颜色)
问题描述
我正在按照 ionic 2 文档设置 iOS 状态栏颜色,但它不起作用.状态栏文本是白色的,这意味着在我的白色背景上它是不可见的.
我在应用构造函数中的代码是:
StatusBar.overlaysWebView(true);StatusBar.styleDefault();我已经使用以下方法导入了 StatusBar:
import {StatusBar} from 'ionic-native';我还检查了 Cordova 状态栏插件是否已安装.
你可以尝试这样在config.xml中添加这个,你要设置的颜色的十六进制值:
对于 ngCordova 或 ionic-native,您可以使用
$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 时,你可以通过颜色名称来设置状态栏的背景颜色.
StatusBar.backgroundColorByName("red");支持的颜色名称有:
黑色、深灰色、浅灰色、白色、灰色、红色、绿色、蓝色、青色、黄色、洋红色、橙色、紫色、棕色或者
通过十六进制字符串设置状态栏的背景颜色.
StatusBar.backgroundColorByHexString("#C0C0C0");还支持 CSS 速记属性.
StatusBar.backgroundColorByHexString("#333");//=>#333333StatusBar.backgroundColorByHexString("#FAB");//=>#FFAABB在 iOS 7 上,当您将 StatusBar.statusBarOverlaysWebView 设置为 false 时,您可以通过十六进制字符串 (#RRGGBB) 设置状态栏的背景颜色.在 WP7 和 WP8 上,您还可以将值指定为 #AARRGGBB,其中 AA 是 alpha 值
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();
I have imported StatusBar using:
import {StatusBar} from 'ionic-native';
I have also checked that the cordova statusbar plugin is installed.
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" />
For ngCordova or ionic-native you can use
$cordovaStatusbar.styleColor('black');
$cordovaStatusbar.styleHex('#000');
Or you check on the statusbar cordova plugin github page there are some ways to change the color of status bar: https://github.com/apache/cordova-plugin-statusbar
For Android:
if (cordova.platformId == 'android') {
StatusBar.backgroundColorByHexString("#333");
}
For iOS
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");
Supported color names are:
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 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).
On WP7 and WP8 you can also specify values as #AARRGGBB, where AA is an alpha value
这篇关于在 ionic 2 应用程序中更改 iOS 状态栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 ionic 2 应用程序中更改 iOS 状态栏颜色
基础教程推荐
- 新的@SystemApi 注解是什么意思,和@hide 有什么区别 2022-01-01
- 如何将多个组件添加到 PickerView? 2022-01-01
- Android:STATE_SELECTED不工作 2022-01-01
- 我的 UIImageView 的任务 2022-01-01
- 在 Android 模拟器中激活网络位置提供程序? 2022-01-01
- 可可/目标C(OSX不是iOS)从子对象访问父对象 2022-01-01
- 突出显示朗读文本(在 iPhone 的故事书类型应用程序中) 2022-01-01
- - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view 如何工作 2022-01-01
- 在 appComponent dagger 2 中动态添加测试模块? 2022-01-01
- 在 iOS8 中无法获得正确的键盘高度值 2022-01-01
