javascript - 标签栏导航器中的图像

标签 javascript react-native react-navigation expo tabbar

我有一个 tabBar 导航器,我想用图像替换图标,它可以工作,但是 activeTintColor 在聚焦时不会改变,尽管它是在 navigationOptions 中设置的,这里是代码:

TabBarIcon组件

export default class TabBarIcon extends React.Component {
  render() {
    return (
      <Image
       source={this.props.source}
       tintColor={this.props.focused ? Colors.tabIconSelected : Colors.tabIconDefault}
      />
    );
  }
}

tabBarNavigator 中的图标

  tabBarIcon: ({ focused, tintColor }) => (
    <Image
      focused={focused}
      source={require('/assets/images/icon.png')}
      tintColor={tintColor}
    />
  ),

最佳答案

对于图像,尝试这样设置

tabBarNavigator 中的图标

tabBarIcon: ({ focused }) => {
        const image = focused
        ? require('./image/HomeActive.png')
        : require('./image/HomeInactive.png')
        return (
            <Image
                source={image}
                style={{height:36, width:24}}
            />
        )
    }

并在tabBarOptions下设置activeTintColor和inactiveTintColor

关于javascript - 标签栏导航器中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53964144/

相关文章:

javascript - 在 ES6 中,如何覆盖父类(super class)中的私有(private)方法?

android - ScrollView React Native 上的多个 onScroll 事件?

javascript - React Native 中的 If/else 语句

javascript - 在React Native中使用装饰器,找不到变量: require

react-native - 从底部选项卡导航器导航到堆栈导航器

javascript - 以最小化模式打开jspanel

javascript - Lodash _.chain 使用展平来查找匹配值数组

javascript - ZingCharts 水平堆叠条形图 X 轴标签被 chop

react-native - React Native BottomTabs 导航到特定选项卡

react-native - react native 导航后退按钮