用户登录
用户注册

分享至

在 ionic 2 应用程序中更改 iOS 状态栏颜色

  • 作者: 寒言笑话内涵图专区
  • 来源: 51数据库
  • 2023-02-09

问题描述

我正在按照 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页面上查看有一些方法可以改变状态栏的颜色:http://www.51sjk.com/Upload/Articles/1/0/342/342870_20230209091932582.jpg

对于 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: http://www.51sjk.com/Upload/Articles/1/0/342/342870_20230209091932582.jpg

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

软件
前端设计
程序设计
Java相关