Shane
Shane

Reputation: 2375

Prevent grey status bar on Android app launch using React Native

I have an Android app using React Native. The app always launches with a grey status bar and I can't find how to prevent that.

In my MainActivity.java I have:

protected void onCreate(Bundle savedInstance) {
    this.setStatusBarToTranslucent();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
         this.setStatusBarColor();
    }

    super.onCreate(savedInstance);
    ....
}

public void setStatusBarToTranslucent() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        View decorView = this.getWindow().getDecorView();
        decorView.setOnApplyWindowInsetsListener((v, insets) -> {
                WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
                return defaultInsets.replaceSystemWindowInsets(
                        defaultInsets.getSystemWindowInsetLeft(),
                        0,
                        defaultInsets.getSystemWindowInsetRight(),
                        defaultInsets.getSystemWindowInsetBottom());
            });

            ViewCompat.requestApplyInsets(decorView);
        } else {
            this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }

    @TargetApi(21)
    public void setStatusBarColor() {
        this.getWindow().setStatusBarColor(Color.parseColor("#33000000"));
    }

This code successfully sets the status bar color and transparency, but it does so after the initial launch and you can clearly see the status bar as grey for a short period.

My app theme is:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@color/my_green</item>
    <item name="android:spinnerStyle">@style/CustomSpinner</item>
</style>

And my targets are:

compileSdkVersion 28
minSdkVersion 19
targetSdkVersion 27

I have tried to set the colorPrimary value of the theme, but that didn't help for the initial launch.

Upvotes: 0

Views: 1252

Answers (1)

Rizwan Atta
Rizwan Atta

Reputation: 3295

The status bar color in android theme is colorPrimaryDark not colorPrimary! ^_^

simply go into native andorid code open theme

you shall have the colorPrimaryDark there change it to your desired color code for the status bar!

Upvotes: 1

Related Questions