简体   繁体   中英

Capacitor transparent status bar overlapping with toolbar in Ionic app for android

I set a transparent status bar in my app.component.html in my ionic app for android as follows:

import { Component,OnInit } from '@angular/core';
import { StatusBar,Style } from "@capacitor/status-bar";
import { Storage } from "@capacitor/storage";
import { Router } from "@angular/router";
@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss'],
})
export class AppComponent implements OnInit {
  constructor(
    public router:Router
  ) {}
  async shouldShowStarterScreen(){
    let hasSeenScreen = await Storage.get({key:"seenScreen"});
    if(hasSeenScreen.value == null){
      this.router.navigate(["starter-screen"]);
    }
  }
  slideOpts = {

  }
  async ngOnInit(){
    this.shouldShowStarterScreen();
  /*  await StatusBar.setStyle({style:Style.Dark})
    StatusBar.setBackgroundColor({
      color:"#3F00FF"
    })*/
    StatusBar.setOverlaysWebView({overlay:true});
  }
}

Its working but there is a slight overlap of the status bar on the app as seen below在此处输入图片说明

What is a quick, suitable way of correcting this

If you want keep overlay, then you can update styles for your toolbar globally in global.scss :

ion-header.md {
    ion-toolbar:first-child {
        --padding-top: 27px;
        height: 66px;
    }
}

This styles suitable for header like this:

<ion-header>
    <ion-toolbar color="primary">
        <ion-title>
            First title
        </ion-title>
    </ion-toolbar>

    <ion-toolbar>
        <ion-title>
            Second title
        </ion-title>
    </ion-toolbar>
</ion-header>

This style is needed only for Android and only for the first toolbar in your ion-header . If you will use pages without ion-header (or with another ion-header structure) you should update your styles in a similar way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM