Ionic 3 - Hide status bar during splash screen sho

2019-07-13 17:00发布

问题:

I have an app with Ionic 3 and in your app.component.ts, i using the Statusbar ionic plugin to hide that, but, this occurs only after platform ready is fired.

How do i hide that during splashscreen? I tried:

– Not hide during splashscreen, only after this hide – Not change background color during splashscreen

Solutions?

回答1:

Android

It seems that there is not elegant way to hide statusbar on app launch. But there is an way to do that.

  1. Find MainActivity.java (maybe platforms/android/src/io/ionic/starter)
  2. Add the below code

import android.view.WindowManager;

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // enable Cordova apps to be started in the background
        Bundle extras = getIntent().getExtras();
        if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
            moveTaskToBack(true);
        }
        // [Hyuck] add this two line below    
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // Set by <content src="index.html" /> in config.xml
        loadUrl(launchUrl);
    }

    // [Hyuck] onStart() is totally new.
    @Override
    public void onStart()
    {
        super.onStart();
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    }
}

IOS

I can only test Android device. So, I just leave the link which may solve your issue