Reactjs 将收割台对准中心

Reactjs 将收割台对准中心,reactjs,react-native,react-navigation,Reactjs,React Native,React Navigation,反应导航:1.0.0-beta.11 反应:16.0.0-alpha.12 反应本机:0.47.1 我将按照教程从传递的道具渲染标题 class ChatScreen extends React.Component { static navigationOptions = ({ navigation }) => ({ title: `Chat with ${navigation.state.params.user}`, // <- Talking bout this

反应导航:1.0.0-beta.11

反应:16.0.0-alpha.12

反应本机:0.47.1

我将按照教程从传递的道具渲染
标题

class ChatScreen extends React.Component {
  static navigationOptions = ({ navigation }) => ({
    title: `Chat with ${navigation.state.params.user}`,   // <- Talking bout this
  });
  render() {
    const { params } = this.props.navigation.state;
    return (
      <View>
        <Text>Chat with {params.user}</Text>
      </View>
    );
  }
}

titleStyle
属性已重命名为
headerTitleStyle
您现在可以通过
headerTitleStyle
将标题样式传递给导航选项,从而设置标题样式

....
headerTitleStyle: {
      color: 'color value',
      textAlign: 'center',
      alignSelf: 'center' //if style using flexbox
}
....

titleStyle
属性已重命名为
headerTitleStyle
您现在可以通过
headerTitleStyle
将标题样式传递给导航选项,从而设置标题样式

....
headerTitleStyle: {
      color: 'color value',
      textAlign: 'center',
      alignSelf: 'center' //if style using flexbox
}
....
如果您的屏幕上有标题左侧后退按钮

不足以成为中心标题。
您必须使用
headerRight:()
才能显示在中间

 static navigationOptions = {
    headerTitleStyle: {
      textAlign: "center",
      alignSelf: "center"
    }
    headerRight: <View><View />
  };
静态导航选项={
头饰样式:{
textAlign:“居中”,
自我定位:“中心”
}
头灯:
};
如果您的屏幕上有标题左键后退按钮

不足以成为中心标题。
您必须使用
headerRight:()
才能显示在中间

 static navigationOptions = {
    headerTitleStyle: {
      textAlign: "center",
      alignSelf: "center"
    }
    headerRight: <View><View />
  };
静态导航选项={
头饰样式:{
textAlign:“居中”,
自我定位:“中心”
}
头灯:
};
根据

您必须使用headerTitleAlign将标题居中。在安卓系统中,它的值默认为左<强>中<强>,而在iOS系统中,它的值为中<强>中<强>

<Stack.Navigator
  initialRouteName='Welcome'
  screenOptions={{
    headerTitleStyle: {
      color: 'white',
      fontSize: 20,
    },
    headerTitleAlign: 'center',
  }}
>
  <Stack.Screen name='Welcome' component={Welcome}/>
</Stack.Navigator>

更多详情:

根据

您必须使用headerTitleAlign将标题居中。在安卓系统中,它的值默认为左<强>中<强>,而在iOS系统中,它的值为中<强>中<强>

<Stack.Navigator
  initialRouteName='Welcome'
  screenOptions={{
    headerTitleStyle: {
      color: 'white',
      fontSize: 20,
    },
    headerTitleAlign: 'center',
  }}
>
  <Stack.Screen name='Welcome' component={Welcome}/>
</Stack.Navigator>


更多详细信息:

谢谢。这解决了问题,但有一个小问题。在更新代码后,它与中心对齐,但不完全是中心。更靠右。我想这是左边箭头的原因,我该怎么修复它呢?我更新了问题中的截图。你能帮我做这个吗?非常感谢。@Somename是的,这是由于“后退”按钮,您可以通过在导航选项中隐藏它来修复它。或者在右侧放置另一个按钮。如果您不想在右侧放置按钮,您可以将
marginRight:40
分配给
headerTitleStyle
,我处理这个问题的方式(我还有一个
headerLeft
)是设置
textallign
并应用
flex:5/6
。谢谢。这解决了问题,但有一个小问题。在更新代码后,它与中心对齐,但不完全是中心。更靠右。我想这是左边箭头的原因,我该怎么修复它呢?我更新了问题中的截图。你能帮我做这个吗?非常感谢。@Somename是的,这是由于“后退”按钮,您可以通过在导航选项中隐藏它来修复它。或者在右侧放置另一个按钮。如果您不想在右侧放置按钮,您可以将
marginRight:40
分配给
headerTitleStyle
,我处理这个问题的方式(我还有一个
headerLeft
)是设置
textallign
并应用
flex:5/6