React Native 状态栏隐藏在导航回屏幕时不起作用(Android)



我用过<StatusBar hidden />,我也在componentWillMount((和render((方法中尝试过StatusBar.setHidden(true),当我第一次打开组件时它可以工作。但是,如果我导航到另一个屏幕,然后再次打开上一个屏幕,大多数情况下会出现状态栏。

有没有办法确保状态栏始终隐藏在每个组件中?

提前致谢

编辑:

主要活动.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));
}
}
}

您可以在活动类的onCreate中使用此代码

if (Build.VERSION.SDK_INT >= 21) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

如果使用SplashActivy,您可以使用此代码

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));
}

最新更新