使用 react-native-vector-icons 未在屏幕上显示图标 android

Icon not displaying on screen android using react-native-vector-icons

我正在使用create-react-native-app. I want to use 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}]} />
      )

  }

我认为你所做的只是一半的事情,所以在运行 npm install 之后你 link 运行 运行 使用第三方本地代码的项目 react-native link?如果是,您是否通过前往 android 工作室并点击播放按钮来重建项目?如果是,那么只需重新启动您的打包程序,我们就可以开始了...

干杯 :)

使用 Create React Native App 时,无法将 react-native link 与原生模块包一起使用。由于 CRNA 项目已加载到 Expo 客户端应用程序中,因此您需要按照 relevant documentation 获取在您的项目中工作的矢量图标。

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

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

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

然后执行命令

react-native 运行-android