如何使StatusBar透明?

Gio*_*lis 5 android statusbar react-native

有谁知道用React Native透明化Android状态栏的方法吗?

不透明,透明。

我也在使用反应导航。

Mou*_*hir 11

这对我在 Android 上有用

<StatusBar
   backgroundColor="transparent"
   translucent={true}
/>
Run Code Online (Sandbox Code Playgroud)


小智 8

只是使用是这样的:经测试:“ react-native”:“ 0.60.4”

<StatusBar translucent backgroundColor="transparent" />
Run Code Online (Sandbox Code Playgroud)

  • 我已经尝试过了,它在 iOS 中工作正常,但在 Android 中却不行(`StatusBar._updatePropsStack`:颜色透明解析为 null 或未定义) (2认同)

ene*_*tli 6

除非您使用 Statusbar 作为组件,否则请尝试此方法。

useFocusEffect(
    useCallback(() => {
      StatusBar.setBarStyle("dark-content");
      Platform.OS === 'android' && StatusBar.setBackgroundColor('transparent');
      StatusBar.setTranslucent(true);
    }, []),
  );
Run Code Online (Sandbox Code Playgroud)

别忘了给paddingTop最外层一些View


小智 0

如果您正在谈论操作系统的状态栏(您下拉以访问 wifi/蓝牙/设置等的状态栏),请尝试将其添加到您的 MainActivity.java 中:

private void hideNavigationBar() {
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
Run Code Online (Sandbox Code Playgroud)

您可以从同一个 MainActivity.java 中调用该函数中的^函数

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    hideNavigationBar();
}
Run Code Online (Sandbox Code Playgroud)

但是,如果您正在谈论应用程序的 StatusBar,请尝试将其添加到您的 App.js 文件中

static navigationOptions = {
    header: null
}
Run Code Online (Sandbox Code Playgroud)

  • 这两种方法都没有用。static navigationOptions = { header: null } 这应该隐藏工具栏/顶栏而不是状态栏。 (2认同)