【问题标题】:React Native status bar hidden doesn't work when navigating back to a screen (Android)导航回屏幕时隐藏的 React Native 状态栏不起作用(Android)
【发布时间】:2018-10-23 23:06:03
【问题描述】:

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

有什么办法可以确保状态栏总是隐藏在每个组件中?

提前致谢

编辑:

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

【问题讨论】:

    标签: android react-native react-native-android statusbar


    【解决方案1】:

    您可以在您的活动课程中的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));
    }
    

    【讨论】:

    • 感谢您的回答!问题是,我的 MainActivity 我没有扩展 Activity,我正在扩展 SpalshActitvity,因为 wix 导航,所以,如果我尝试添加 onCreate,我会收到错误消息。有什么建议吗?
    • 我在尝试运行此程序时遇到很多错误。如果有帮助,我将使用我的 mainActivity 代码编辑我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多