React Native,更改React Navigation标头样式

user818700:

我正在我的React Native应用程序中实现React Navigation,并且想要更改标题的背景和前景色。我有以下几点:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';
import { StackNavigator } from 'react-navigation';

export default class ReactNativePlayground extends Component {

  static navigationOptions = {
    title: 'Welcome',
  };

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit index.android.js
        </Text>
        <Text style={styles.instructions}>
          Double tap R on your keyboard to reload,{'\n'}
          Shake or press menu button for dev menu
        </Text>
      </View>
    );
  }

}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

const SimpleApp = StackNavigator({
  Home: { screen: ReactNativePlayground }
});

AppRegistry.registerComponent('ReactNativePlayground', () => SimpleApp);

默认情况下,标题的背景颜色为白色,前景为黑色。我也看过了React Navigation的文档,但是找不到在哪里显示如何设置样式。有什么帮助吗?

cssko:

在更新版本的React Navigation中,您有一个更扁平的设置对象,如下所示:

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

不建议使用的答案:

根据文档,在这里,您可以修改navigationOptions对象。尝试类似的方法:

static navigationOptions = {
    title: 'Welcome',
    header: {
        style: {{ backgroundColor: 'red' }},
        titleStyle: {{ color: 'green' }},
    }
}

请不要实际使用这些颜色!

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

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

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

React Navigation 6.0 双标头问题

React Navigation 5标头重叠

使用React Native中的React Navigation在navigationOptions中将标头设置为null?

标头未显示在react-navigation-drawer React-Native中

如何设置react-admin Datagrid的标头样式?

标头能否在react-navigation中滚动显示内容?

如何从 react-navigation 标头调用函数?

React Navigation 5-标头未显示

在Focus React Native上更改TextInput样式

如何更改外部 React Native 模块的样式

React Native:更改ListView项目的样式

React native-动态更改样式

React Native:SectionList 从 renderItem 获取标头

React Native中的视差标头问题

嵌套在Stack Navigation v5中的React Native Tab-更新标头的最佳实践

react-native React-Navigation头按钮testID

React Native:在方向更改上应用了不同的样式

在React Native中按下时更改按钮样式

如何在React Native中更改TextInput占位符的样式?

如何在React Native中更改特定列的样式?

如何从 React Native 的列表中更改所选文本的样式

React Native:高程样式属性-更改阴影方向

更改样式和属性 onTextChange - React Native

OnPress从循环更改组件样式-带钩子的React Native

当TextInput onFocus和onBlur.React-Native更改样式

在Focus React Native Paper上更改TextInput样式

如何在React Native中更改语句中的单词样式?

使用 React Native 在 onPress 后更改按钮样式

React Navigation 5:在BottomTabNavigator上实现自定义标头