ionic3 沉浸式状态栏

预览

TIM图片20181208181258.png

环境

测试机型:OPPO R15
安卓版本:8.1
靠ionic3原生的status bar插件来实现这种效果是不可能的,由于网上找到的很多办法都只能实现半透明效果,所以自己结合了一些网上大佬的方法。

代码

照着改就行了
\platforms\android\app\src\main\java\io\ionic\starter\MainActivity.java

import android.os.Bundle;
import org.apache.cordova.*;
import android.os.Build;
import android.view.View;

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
                
        getWindow().getDecorView().setSystemUiVisibility(
              View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        );
        

        // enable Cordova apps to be started in the background
        Bundle extras = getIntent().getExtras();
        if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
            moveTaskToBack(true);
        }

        // Set by  in config.xml
        loadUrl(launchUrl);
    }
        
}

\platforms\android\app\src\main\java\org\apache\cordova\statusbar\StatusBar.java

this.cordova.getActivity().runOnUiThread(new Runnable() {
    @Override
    public void run() {
        Window window = cordova.getActivity().getWindow();
        window.setStatusBarColor(Color.TRANSPARENT);
        window.setNavigationBarColor(Color.TRANSPARENT);
        setStatusBarStyle(preferences.getString("StatusBarStyle", "lightcontent"));
    }
 });

你可能感兴趣的:(ionic3 沉浸式状态栏)