【问题标题】:React Native StatusBar: dark-content not working on androidReact Native StatusBar:黑暗内容不适用于android
【发布时间】:2020-05-05 10:03:59
【问题描述】:

我正在尝试将标题的颜色和状态栏的图标更改为黑色。 因此,根据 react-native 状态栏文档,我将 barStyle 设置为 dark-content 但没有任何变化。

<StatusBar barStyle="dark-content" backgroundColor={'white'} />

【问题讨论】:

  • 嗨..你能解决它吗?
  • 同样的问题,'dark-content' 在 android 上不起作用。将显示它的默认道具('light-content')。

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


【解决方案1】:

您可以尝试执行以下操作:

import {StatusBar} from "react-native"

...

StatusBar.setBackgroundColor('white');
StatusBar.setBarStyle('dark-content');

使用 useEffectcomponentDidMount 方法。

【讨论】:

    【解决方案2】:

    如果您使用的是Expo,您应该使用他们自己的Statusbar。 你可以通过运行来安装它:

    expo install expo-status-bar
    

    并像这样修改它:

    import { StatusBar } from 'expo-status-bar';
    ...
       <StatusBar style="dark" />
    ...
    

    否则你可能想尝试通过运行来升级你的 react native 版本:

    npx react-native upgrade
    

    【讨论】:

      【解决方案3】:

      正如this issue 所说,您可以尝试升级到较新版本的 react-native(如果您的不是最新版本),看看它是否有效。

      【讨论】:

      • 那个问题是针对 iOs 的,但这里的问题是针对 android 的。
      【解决方案4】:

      我遇到了同样的问题。确保您的“StatusBar”组件是从“react-native”而不是“expo-status-bar”导入的。现在它对我有用,因为我正在使用“react-native”中的“StatusBar”组件

      【讨论】:

        猜你喜欢
        • 2020-03-25
        • 2017-06-08
        • 1970-01-01
        • 2022-01-11
        • 2021-08-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多