简体   繁体   English

如何在导航容器中将 header 的文本居中?

[英]How do I center the text for the header in the Navigation Container?

I am trying to center the text for a header, but can't seem to implement it.我试图将 header 的文本居中,但似乎无法实现它。 I am following a tutorial on this and even though I'm following it step-by-step the text is not aligning in the center.我正在关注这方面的教程,即使我一步一步地关注它,文本也没有在中心对齐。 I want it to center as I will be using a backHeaderTitle using the useLayoutEffect to return to the previous screen.我希望它居中,因为我将使用 backHeaderTitle 使用 useLayoutEffect 返回到前一个屏幕。 I would appreciate any help as I have been stuck for a few days on this.我将不胜感激任何帮助,因为我已经被困了几天。

\\ \\

import "react-native-gesture-handler";
import React from "react"; 
import { StyleSheet, Text, View } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/
stack";
import LoginScreen from "./screens/LoginScreen";

const Stack = createStackNavigator();
const globalScreenOptions = {
  headerStyle: {backgroundColor: "#2C6BED"},
  headerTitleStyle: {color: "white"},
  headerTintColor: "white",
}
export default function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator screenOptions={globalScreenOptions}>
        <Stack.Screen  
        name="Login" 
        component={LoginScreen}
        
        />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

\\ \\

Try adding this to your globalScreenOptions尝试将此添加到您的 globalScreenOptions

    headerTitleAlign: 'center'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM