Android 的 React Navigation Stack Navigator 后退按钮样式

React Navigation Stack Navigator Back Button Styling for Android

我实现了 Stack Navigator 如下:

const MainNav = StackNavigator({
    notes: { screen: NotesScreen },
    addNote: { screen: AddNoteScreen }
}, {
    initialRouteName: 'notes'
});

现在,当我从 NotesScreen 转到 AddNoteScreen 时,我得到了预期的后退箭头。但是,我使用以下 navigationOptions:

AddNoteScreen 设置了 header 的样式
static navigationOptions = () => ({
    title: 'Add a note',
    headerStyle: {
        height: Platform.OS === 'android' ? 54 + STATUS_BAR_HEIGHT : 54,
        backgroundColor: '#2196F3'
    },
    headerTitleStyle: {
        marginTop: Platform.OS === 'android' ? STATUS_BAR_HEIGHT : 0,
        color: 'white'
    }
})

现在 headerTitleStyle 不会影响 Android 上的后退箭头。如何使 android 上的后退箭头采用与 headerTitleStyle 相同的样式?

这是当前问题的图像:

navigationOptions中有一个属性 headerTintColor可以用来改变后退按钮图标的颜色。除了现在 react-navigation v1.0.0-beta.11 中没有其他选项可以自定义后退按钮。

static navigationOptions = () => ({
    title: 'Add a note',
    headerStyle: {
        height: Platform.OS === 'android' ? 54 + STATUS_BAR_HEIGHT : 54,
        backgroundColor: '#2196F3'
    },
    headerTitleStyle: {
        marginTop: Platform.OS === 'android' ? STATUS_BAR_HEIGHT : 0,
        color: 'white'
    },
    headerTintColor: 'white'
})

顺便说一句,不用在 header 样式中处理状态栏高度,只需在根组件内渲染 react-native 的 StatusBar 组件,例如

import {
  AppRegistry,
  View,
  StatusBar,
} from 'react-native';

class AppWithStatusBar extends Component {

  render() {
    return(
      <View style={{flex: 1}}>
        <StatusBar barStyle="light-content"/>
        <MainNav />
      </View>
    );
  }
}

然后渲染这个 'AppWithStatusBar' 组件

AppRegistry.registerComponent('your_app', () => AppWithStatusBar);

为什么不在 Android 中隐藏状态栏? :

import { View, StatusBar } from 'react-native';

class App extends React.Component {

  render() {
    return (

     <View style={{flex : 1}}>
       <StatusBar hidden = {true}/>
       <Search/>
     </View>

    );
  }
}