【问题标题】:Change status bar color on iOS and Android in React Native在 React Native 中更改 iOS 和 Android 上的状态栏颜色
【发布时间】:2019-11-04 14:16:41
【问题描述】:

我在使用 React Native 时遇到了一些问题。我有一个需要自定义标题的屏幕(带有图标和更多内容),所以在navigationOptions 中我将使用headerTitle 而不是title

问题是,当使用headerTitle 时,组件中不包含状态栏。所以我有这样的事情:

headerTitle: () => <MyHeader />

然后:

const MyHeader = props => {
  return(
    <View style={{flex: 1, backgroundColor: 'red', height: '100%', padding: 10, justifyContent: 'center'}}>
      <Text style={{color: 'white'}}>Testing</Text>
    </View>
  )
}

我明白了:

我试过这样做:

How to set iOS status bar background color in React Native?

但是没有用。

这是我想要的结果:

我可以在navigationOptions 中使用headerStyleheaderTitleStyle 来做到这一点,但是我不能使用自定义组件...

【问题讨论】:

    标签: reactjs react-native


    【解决方案1】:

    你可以使用headerStyle

    const MyHeader = props => {
      return(
        <View style={{flex: 1, backgroundColor: 'red', height: '100%', padding: 10, justifyContent: 'center'}}>
          <Text style={{color: 'white'}}>Testing</Text>
        </View>
      )
    }
    
    static navigationOptions = {
        headerTitle: () => <MyHeader />,
        headerStyle: {
          backgroundColor: 'red',
        }
      };
    

    IOS

    安卓

    【讨论】:

      【解决方案2】:

      简单。使用 StatusBarIOS 组件。

      【讨论】:

      • 实际上,经过一些测试,我发现我可以将headerStyle AND headerTitle 与自定义组件一起使用,它仍然可以工作!
      猜你喜欢
      • 1970-01-01
      • 2019-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-03
      • 2023-03-31
      • 1970-01-01
      • 2017-10-10
      相关资源
      最近更新 更多