React Native:NavigationOptions中的标题样式不起作用

瑙曼·坦威尔

我对本机很陌生。我正在尝试为我的应用设置一些全局标题样式,但是它不起作用

route.js

import React, { Component } from 'react';
import { View } from 'react-native';
import { createStackNavigator, createAppContainer } from "react-navigation";
import SplashScreen from '../screens/SplashScreen';
import CalendarScreeen from '../screens/CalendarScreen';

const NavStack = createStackNavigator(
    {
        Splash: {
            screen: SplashScreen,
            navigationOptions: {
                header: null
            },
        },
        Calendar: {
            screen: CalendarScreeen,
            navigationOptions: {
                title: 'Calendar',
            },
        },
    },
    {
        initialRouteName: 'Calendar',
        navigationOptions: {
            headerStyle: {
                backgroundColor: '#28F1A6',
                elevation: 0,
                shadowOpacity: 0
            },
            headerTintColor: '#333333',
            headerTitleStyle: {
                fontWeight: 'bold',
                color: '#ffffff'
            }
        }
       
    }

);

const Routes = createAppContainer(NavStack);
export default Routes;

现在,我知道我可以在班级组件中做类似的事情

static navigationOptions = {
  title: 'Chat',
  headerStyle: { backgroundColor: 'red' },
  headerTitleStyle: { color: 'green' },
}

正如这里可能提到的

但我想通过我实现同样的目标 route.js

我也尝试过defaultNavigationOptions文档中提到的那样

但是没有运气!

昂迈特·海因

我认为您使用的是反应导航版本3。如果是,则将navigationOptions更改为defaultNavigationOptions

{
        initialRouteName: 'Calendar',
        defaultNavigationOptions: {
            headerStyle: {
                backgroundColor: '#28F1A6',
                elevation: 0,
                shadowOpacity: 0
            },
            headerTintColor: '#333333',
            headerTitleStyle: {
                fontWeight: 'bold',
                color: '#ffffff'
            }
        }

}

它应该工作。https://snack.expo.io/ByGrHdAC7

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

PushNotificationIOS.presentLocalNotification()在react-native中不起作用

开关盒在React Native中不起作用

图像resizeMode ='contain'在React Native中不起作用

为什么我的裁判在React Native中不起作用?

在React Native中,样式在所有文本视图中均不起作用

React Native:iOS中的透明Stack Navigator不起作用

onNavigationStateChange在Android React Native中不起作用

连接分派在React Native中不起作用

clearTimeout在React Native中不起作用

React Native:在NavigationOptions.tabBarIcon中返回图像不起作用

posesEnabled:false在React Native中不起作用

订阅在React Native中不起作用?

onPress在React Native Flatlist中不起作用

flex在react-native中的ScrollView中不起作用

下拉样式在React类中不起作用

获取在 React Native ios 中不起作用

Tab 中的 react-native-maps 不起作用

React Native 中的垂直居中不起作用

在 React Native fetch 方法中解析 JSON 不起作用

视图样式在 React Native 中不起作用

React Native boderStyle 样式不起作用

clearInterval() 在 React Native 功能组件中不起作用

React 中的 :hover 和 :focus 内联样式不起作用

React.js 中的样式组件 - props 不起作用

REACT NATIVE - this.setState 在 onChangeText 中不起作用

useScrollToTop 在 useEffect 中不起作用?(React Native Expo)

React typescript 样式的组件滑块在组件中不起作用

React Native:在TestFlight中显示图像不起作用

React Native“样式组件”不起作用