在React Native中在iOS和Android上更改状态栏颜色

我在使用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>
  )
}

我明白了:

在React Native中在iOS和Android上更改状态栏颜色

我尝试这样做:

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

但是没有用。

这是我的预期结果:

在React Native中在iOS和Android上更改状态栏颜色

我可以使用headerStyle中的headerTitleStylenavigationOptions来做到这一点,但是我不能使用自定义组件...

MztKid 回答:在React Native中在iOS和Android上更改状态栏颜色

您可以使用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

enter image description here

Android

enter image description here

,

简单。使用StatusBarIOS组件。

本文链接:https://www.f2er.com/3166066.html

大家都在问