【问题标题】:How to change colour styles for tab navigator in react native?如何在 React Native 中更改选项卡导航器的颜色样式?
【发布时间】:2017-11-10 08:49:50
【问题描述】:

我是一个反应原生的新手。我在主屏幕上使用标签导航器,但不知道如何更改活动和非活动标签颜色样式。

export const MyApp = TabNavigator({
  Asset: {
   screen: AssetScreen
  },
 Sensors: {
  screen: sensorsStack
 },
 Settings: {
  screen: settingStack
 },
},{
tabBarPosition: 'bottom',
animationEnabled: true,
swipeEnabled:false,
tabBarOptions: {
upperCaseLabel: false,
showIcon: true,
activeBackgroundColor:'#2394C7',
inactiveBackgroundColor:'grey',
tabStyle:{
    marginTop:10,
    height :53,
    borderRightWidth:1
},
labelStyle: {
    fontSize: 15,
    fontWeight:'bold',
     marginTop: 0,
     color :'#ffffff'
  },
 },
});

任何建议将不胜感激。

【问题讨论】:

    标签: react-native tabnavigator


    【解决方案1】:

    您可以使用 tabBarOptions 下的 activeBackgroundColorinactiveBackgroundColor 属性来设置活动和非活动标签的颜色。

    更多信息请查看文档here

    【讨论】:

    • 这两个属性(activeBackgroundColor、inactiveBackgroundColor)对我来说可以为“活动”和“非活动”标签上色。即使我尝试使用您的 tabBarOptions (已编辑),它也按预期工作。
    • 我只在iOS中检查过,在Android中没有检查过。
    • 它在 ios 中工作,但在 android 中找不到。无论如何都可以在这两种设备上执行此操作。
    • 是的,在 android 中它不起作用,你需要为 android 添加更多样式。我在tabBarOptions 下添加了indicatorStyle: { backgroundColor: '#2394C7', height: 53 }, style: { backgroundColor: 'grey' } 之类的样式,并且工作正常。看看android问题(github.com/react-community/react-navigation/issues/1485)
    猜你喜欢
    • 2020-11-11
    • 2018-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多