【问题标题】:Ionic 4 Android App, unable to change background color of status barIonic 4 Android App,无法更改状态栏的背景颜色
【发布时间】:2019-05-13 00:30:24
【问题描述】:

我正在构建一个 ionic 4 应用程序,在 android 上运行时,状态栏是黑色的,我想更改它,但我无法弄清楚。

我尝试更改 config.xml 中的首选项,OverlayWebView true 和 false,并尝试只使用 this.statusBar.backroundcolor... 的东西。没有任何效果。 状态栏插件已安装。

Config.xml:    
<preference name="ScrollEnabled" value="false" />
<preference name="android-minSdkVersion" value="19" />
<preference name="BackupWebStorage" value="none" />
<preference name="SplashMaintainAspectRatio" value="true" />
<preference name="FadeSplashScreenDuration" value="300" />
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="3000" />
<preference name="StatusBarBackgroundColor" value="#ffffff" />
<preference name="StatusBarOverlaysWebView" value="true" />


App.component.ts

import { StatusBar } from '@ionic-native/status-bar/ngx';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html'
  })
 export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar
  ) {
     this.initializeApp();
  }


  initializeApp() {
  this.platform.ready().then(() => {
  this.statusBar.styleDefault();
  this.splashScreen.hide();
  this.statusBar.overlaysWebView(true);
  this.statusBar.backgroundColorByHexString('#ffffff');
    });
   }
 }

我想更改显示时间、电池电量等状态栏的颜色,但无论我做什么,它都保持黑色。

【问题讨论】:

  • 删除状态栏的所有行。只要把这个 this.statusBar.backgroundColorByHexString('#ffffff'); config.xml 也不需要任何更改
  • 很抱歉,这不起作用。
  • 我使用上面对我有用的行遇到了同样的问题。

标签: android ionic-framework ionic4


【解决方案1】:

我现在设法更改了颜色,但必须在 Android Studio 中使用 android:statusBarColor 进行更改。仍然会感谢在 ionic 中执行此操作的方法。

 <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:background">@null</item>
    <item name="android:statusBarColor">@color/colorPrimary</item>
 </style>


 <style name="AppTheme.NoActionBarLaunch" parent="AppTheme.NoActionBar">
    <item name="android:background">@drawable/splash</item>
    <item name="android:statusBarColor">@color/colorPrimary</item>
 </style>
</resources>

【讨论】:

    猜你喜欢
    • 2015-09-26
    • 2019-11-20
    • 2012-02-21
    • 2016-10-16
    • 1970-01-01
    • 2015-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多