1

似乎除了backgroundColor没有其他东西对headerStyle.

 const defaultNavOptions = {
  headerBackTitle: 'Back',
  headerStyle: {
    backgroundColor: colors.secondary,
    height: 100,
  },

然后我传递选项:

 <Stack.Navigator
      initialRouteName={'Home'}
      screenOptions={({ navigation }) => ({
        ...defaultNavOptions,
        headerLeft: () => (
          <Icon
            name="menu-open"
            size={30}
            color={colors.primary}
            onPress={() => navigation.openDrawer()}
          />
        ),
      })}
    >

难道我做错了什么?
有没有办法设置标题的高度?
提前致谢。

4

2 回答 2

0
<Stack.Navigator
      initialRouteName={'Home'}
      screenOptions={({ navigation }) => ({
        headerStyle: { backgroundColor: 'tomato', height: 100 },
        headerLeft: () => (
          <Icon
            name="menu-open"
            size={30}
            color={colors.primary}
            onPress={() => navigation.openDrawer()}
          />
        ),
      })}
    >
于 2021-12-20T10:06:56.843 回答
0

我发现在每个屏幕上使用选项参数而不是为整个导航器拾取headerStyle

const defaultNavigationOptions = {
    headerBackTitle: 'Back',
    headerStyle: {
        backgroundColor: colors.secondary,
        height: 100,
    }
}
<Stack.Navigator initialRouteName={'Home'}>
    <Stack.Screen
        name="Home"
        component={Home}
        options={defaultNavigationOptions}
    />
    <Stack.Screen
        name="ScreenWithHeaderLeft"
        component={ScreenWithHeaderLeft}
        options={{
            ...defaultNavigationOptions,
            headerLeft: () => <Icon name="menu-open" size={30} color={colors.primary} />,
        }}
    />
</Stack.Navigator>
于 2021-12-20T16:46:21.827 回答