【发布时间】:2019-05-02 08:56:00
【问题描述】:
我对 react-native 还很陌生。我正在尝试为我的应用设置一些全局标题样式,但它不起作用
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' },
}
正如这里提到的possible alternative
但我想通过我的route.js实现同样的目标
我也试过defaultNavigationOptions,就像docs中提到的那样
但是没有运气!!
【问题讨论】:
标签: reactjs react-native react-navigation