【问题标题】:How to change navigation header color in react native?如何在本机反应中更改导航标题颜色?
【发布时间】:2018-05-04 06:26:57
【问题描述】:

如何在 React Native 应用中更改导航标题的颜色?

我尝试初始化背景颜色,但没有成功。

下面是navigationOptions的代码sn-p:

static navigationOptions = ({ navigation }) => ({
    header: props => <Header 
        navigation={navigation}
        title={'Dashboard'}
        toggleDrawer
    />
})

另外,可以设置状态栏颜色吗?

【问题讨论】:

  • 由于您提供的是custom header,因此您需要更改那里的样式。
  • 自定义标头@PritishVaidya 中没有更改

标签: android react-native react-navigation android-statusbar


【解决方案1】:

你可以用headerStyle改变它:

navigationOptions = {
  headerStyle: {
    backgroundColor: 'red',
  },
);

状态栏见https://facebook.github.io/react-native/docs/statusbar.html

【讨论】:

  • navigationOptions?只需用这个替换你当前的(添加static 关键字)。你需要一个自定义的header 组件吗?您对其进行了哪些更改?
  • 我只想为栏添加颜色以及当前属性。
  • 不,它根本不提供任何颜色。它变为白色,所有其他属性都会消失。
  • 使用自定义标头更改它。谢谢!
  • 链接失效了,应该是:reactnative.dev/docs/statusbar
【解决方案2】:

像这样使用它:

static navigationOptions = () => ({
    title: 'Home',
    headerTintColor: '#cccccc',
    headerStyle: {
      backgroundColor: '#000',
    },      
  });

【讨论】:

    【解决方案3】:

    您可以使用以下参数设置状态栏颜色:

    <StatusBar backgroundColor='blue' barStyle='light-content' />
    

    【讨论】:

    • 我还需要了解操作栏和状态栏。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-10
    • 2023-01-05
    • 2022-01-18
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多