【问题标题】:Icon not displaying on screen android using react-native-vector-icons使用 react-native-vector-icons 图标未在屏幕上显示 android
【发布时间】:2017-04-29 17:52:57
【问题描述】:

我正在使用create-react-native-app。我想用react-native-vector-icons

但它在 android 屏幕上没有显示任何内容(我在 expo 应用程序上查看它)

这是我所做的:

App.js:

       const Courses = TabNavigator({
  ReactCourses: { screen: ReactCourses },
  NativeCourses: { screen: NativeCourses },
}, {
  tabBarOptions: {
    activeTintColor: '#e91e63',
    swipeEnabled: true,
    showIcon:true,
  },
});

ReactCourses.js:

     import Icon from 'react-native-vector-icons/MaterialIcons';
    static navigationOptions = {
    tabBarLabel: 'React Courses',
    tabBarIcon:({ tintColor }) => (
        <Icon
          name={'home'}
          size={26}
          style={[styles.icon, {color: tintColor}]} />
      )

  }

【问题讨论】:

    标签: android react-native react-navigation expo create-react-native-app


    【解决方案1】:

    在android/app/build.gradle中添加以下内容

    申请自:“../../node_modules/react-native-vector-icons/fonts.gradle”

    然后执行命令

    react-native run-android

    【讨论】:

      【解决方案2】:

      使用 Create React Native App 时,不能将 react-native link 与原生模块包一起使用。由于 CRNA 项目是在 Expo 客户端应用程序中加载的,因此您需要关注 relevant documentation 以在您的项目中使用矢量图标。

      另外,请确保您使用的是 .babelrc 中的 Expo 预设。它应该看起来像 the one provided in the template project

      【讨论】:

        【解决方案3】:

        我认为您所做的只是一半,所以在运行npm install 之后,您是否通过运行react-native link 将项目与第三方的本机代码链接起来?如果是,您是否通过转到 android studio 并点击播放按钮来重建项目?如果是,那么只需重新启动您的打包程序,我们就可以开始了...

        干杯:)

        【讨论】:

        • 是的,我做了 react-native 链接,但是为什么我需要 android studio 来重建。我认为 create-react-native-app 工具是为了不需要 android 和 xcode。
        • 我也做了npm run android 并在android 模拟器中运行应用程序......仍然面临同样的问题。
        • 你重建项目了吗?
        • 请注意 Create React Native App 不支持使用 react-native link 除非您已经弹出,OP 没有说他们这样做。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-16
        相关资源
        最近更新 更多