首页 > 解决方案 > 反应导航更改材质顶部选项卡的背景颜色

问题描述

我想在反应导航 5 中更改材质顶部选项卡的边框底部颜色和背景颜色

我尝试了下面的代码,但是当我更改 tabStyle 的背景颜色时,indicatorStyle 边框底部颜色不起作用,但是当我删除 tabstyle 时,指示器样式正在工作。

 <Nav />
      <tTab.Navigator
      tabBarOptions={{
          tabStyle: { backgroundColor: "black" },
          indicatorStyle: {
            borderBottomColor: "#50d3a7",
            borderBottomWidth: 2,
          },
        }}
        initialRouteName="Points"
      >
        <tTab.Screen name="Points" component={pointleftScreen} />
        <tTab.Screen name="Daily Rewards" component={calendarScreen} />
      </tTab.Navigator>

我在这里添加了示例 - https://snack.expo.io/@adjmpw/chaneg-borderbottom-and-background

标签: react-nativereact-native-navigation

解决方案


你将不得不使用barOptionsprop 来定制这些东西

barStyle = {{
  backgroundColor: '#694fad', //Color of your choice
  borderBottomColor: '#50d3a7',
  borderBottomWidth: 2,
}}

你将不得不像这样使用它

<tTab.Navigator
  initialRouteName="Points"
  barStyle={{
    backgroundColor: '#694fad', //Color of your choice
    borderBottomColor: '#50d3a7',
    borderBottomWidth: 2,
  }}>
  >
  <tTab.Screen name="Points" component={pointleftScreen} />
  <tTab.Screen name="Daily Rewards" component={calendarScreen} />
</tTab.Navigator>

工作示例


推荐阅读