本文介绍了我们如何将 react-navigation 标题的标题居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

React-navigation 文档还很年轻,阅读这些问题对我来说并不是很有效(每个版本都有变化)有没有人有一种工作方法可以使用 react-navigation 在 React Native 中?

解决方案

使用

2019/03/12 修改:

在 2018 年,在 react-navigation v2 发布(2018 年 4 月 7 日)之后,由于某种原因 alignSelf 不再工作.这是新的工作方式,使用 headerLayoutPreset.来自@HasanSH:

const HomeActivity_StackNavigator = createStackNavigator({主页:{屏幕:主},}, {headerLayoutPreset: 'center'});

React-navigation docs are still young, and reading through the issues is not working quite much for me (changes on each version) does anyone have a working method to center title in Android using react-navigation in React Native?

解决方案

Use headerTitleStyle:

static navigationOptions = {
    headerTitleStyle: { alignSelf: 'center' },
    title: 'Center Title',
}

Modified 2019/03/12:

In year of 2018, after react-navigation v2 release (7 Apr 2018), for some reason alignSelf was not working anymore. Here it is the new working way, using headerLayoutPreset. from @HasanSH:

const HomeActivity_StackNavigator = createStackNavigator({
    Home: {screen: Main},
}, {headerLayoutPreset: 'center'});

这篇关于我们如何将 react-navigation 标题的标题居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 00:39