react-native中使用图标库react-native-vector-icons

1.先给项目添加该库;

npm install --save react-native-vector-icons

 

配置:

1.自动配置:(我这边使用这种配置方法报错了,然后使用的下面手动配置方法)

react-native link react-native-vector-icons

 

2.手动配置:

第一步:将node_modules/react-native-vector-icons/Fonts中你所需要使用到的字体文件复制到/app/src/main/assets/fonts ,没有assets文件夹的新建即可;

第二步:android/app/ build.gradle:

dependencies {
   compile fileTree(dir: "libs", include: ["*.jar"])
   compile project(':react-native-vector-icons') //添加此文件
   compile "com.android.support:appcompat-v7:23.0.1"
   compile "com.facebook.react:react-native:+"  // From node_modules
}

第三步.配置 android/settings.gradle:

include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')

第四步:修改android\app\src\main\java\com\myproject\MainApplication.java:

 

import com.facebook.react.ReactApplication;

import com.facebook.react.ReactNativeHost;

import com.facebook.react.ReactPackage;

import com.facebook.react.shell.MainReactPackage;

import com.oblador.vectoricons.VectorIconsPackage;//新增此文件

import com.facebook.soloader.SoLoader;

 

@Override
protected List getPackages() {
 return Arrays.asList(
        new MainReactPackage(),
        new VectorIconsPackage()//新增此文件
        );
}

第五步:重新react-native run-android即可。
 

你可能感兴趣的:(react-native)