反应导航标题

时间:2020-04-08 10:00:01

标签: reactjs react-native react-native-android

我使用带有本机导航版本^ 4.3.7的本机0.62.0和createMaterialBottomTabNavigator。我尝试搜索并实施他们的解决方案,但似乎都没有用。我想将文本放在标题中。这就是我尝试过的。

static navigationOptions = ({ navigation }) => ({
    title: 'Profile',
    headerTitleStyle: { flex: 1, textAlign: 'center', color: 'white', fontSize: 20, alignSelf: 'center' , },
    headerTintColor: 'white',
    headerStyle: {
        backgroundColor: '#4169E1',
    },
})

2 个答案:

答案 0 :(得分:1)

尝试一下:

static navigationOptions = ({ navigation }) => ({
    title: 'Profile',
    headerTitleStyle: { flex: 1, textAlign: 'center', color: 'white', fontSize: 20, alignSelf: 'center' , },
    headerTintColor: 'white',
    headerStyle: {
        backgroundColor: '#4169E1',
    },
    headerTitleAlign: 'center',
})

答案 1 :(得分:0)

在删除alignSelf: 'center' ,之后再试。以下代码对我有用。

  defaultNavigationOptions: ({ navigation }) => {
        return {
          headerStyle: {
            backgroundColor: '#1e89f4'
          },
          headerTitle: 'Statistics',
          headerTintColor: '#fff',
          headerTitleStyle: {
            fontWeight: 'bold',
            textAlign: 'center',
            flex: 1
          },
          headerLeft: (
            <View style={{ paddingLeft: 13 }}>
              <FontAwesomeIcon
                size={25}
                color='#fff'
                icon={faBars}
                onPress={() => navigation.openDrawer()}
              />
            </View>
          ),
          headerRight: <View />
        };
      }
相关问题