Diogo Carvalho
Diogo Carvalho

Reputation: 255

React Native status bar hidden doesn't work when navigating back to a screen (Android)

I have used <StatusBar hidden /> and I've also tried StatusBar.setHidden(true) both in componentWillMount() and in the render() methods and it works when I open a component for the first time. But if I navigate to another screen and then open the previous screen again, most of the times the status bar appears.

Is there any way to ensure the status bar is always hidden in every component?

Thanks in advance

EDIT:

MainActivity.java

package com.wixnav2;

import com.reactnativenavigation.controllers.SplashActivity;

import android.content.Intent; 
import android.content.res.Configuration; 

public class MainActivity extends SplashActivity {

@Override
public void onConfigurationChanged(Configuration newConfig) {
  super.onConfigurationChanged(newConfig);
  Intent intent = new Intent("onConfigurationChanged");
  intent.putExtra("newConfig", newConfig);
  this.sendBroadcast(intent);
}

@Override
public void onCreate(Bundle savedInstanceState) {
  Window window = getWindow();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
     window.setStatusBarColor(ContextCompat.getColor(this, R.color.transparent));
    }
  }
}

Upvotes: 1

Views: 643

Answers (1)

Mostafa Pirhayati
Mostafa Pirhayati

Reputation: 433

you can use this code in your onCreate in your activity class

 if (Build.VERSION.SDK_INT >= 21) {

  requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        }

if use SplashActivy you can use this code

Window window = getWindow();
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(ContextCompat.getColor(this, R.color.transparent));
}

Upvotes: 1

Related Questions