简体   繁体   English

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

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

I am using create-react-native-app .我正在使用create-react-native-app I want to use react-native-vector-icons我想使用react-native-vector-icons

But its not showing anything on android screen (I am viewing it on expo app)但它没有在 android 屏幕上显示任何内容(我在 expo 应用程序上查看它)

Here is what I did:这是我所做的:

App.js:应用程序.js:

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

ReactCourses.js: 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}]} />
      )

  }

Add the following things in android/app/build.gradle在 android/app/build.gradle 添加以下内容

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

And then execute the command然后执行命令

react-native run-android react-native run-android

When using Create React Native App, it's not possible to use react-native link with native module packages.使用 Create React Native App 时,无法将react-native link与原生模块包一起使用。 Because CRNA projects are loaded in the Expo client app, you'll want to follow the relevant documentation to get vector icons working in your project.因为 CRNA 项目是在 Expo 客户端应用程序中加载的,所以您需要按照相关文档来让矢量图标在您的项目中工作。

Also, make sure that you're using the Expo preset in .babelrc .另外,请确保您使用的是.babelrc的 Expo 预设。 It should look like the one provided in the template project .它应该看起来像模板项目中提供的那个

I think what you did is just a half thing, so after running npm install did you link the project with the third party's native code by running react-native link ?我认为你所做的只是一半,所以在运行npm install之后,你是否通过运行react-native link将项目与第三方的本机代码react-native link if yes, did you rebuild the project by going to android studio and hit play button?if yes then just restart your packager and we are good to go...如果是,您是否通过转到 android studio 并点击播放按钮来重建项目?如果是,那么只需重新启动您的打包程序,我们就可以开始了...

Cheers :)干杯:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM