第一步:在react-native 工程目录下通过npm安装react-native-vector-icons

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

第二步:分别为android和ios做一些相应的配置

Android:

在android/app/build.gradle

中增加如下脚本:

project.ext.vectoricons = [    iconFontNames: [ 'MaterialIcons.ttf', 'EvilIcons.ttf' ] // Name of the font files you want to copy]apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
在node-modules 中找到
react-native-vector-icons库,将Fonts 文件夹拷贝到android/app/src/main/assets/fonts如果没有assets/fonts 新建即可在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')
include ':react-native-vector-icons'的作用时在编译android项目的时候
react-native-vector-icons会作为一个module加入编译。
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')是指定
react-native-vector-icons的具体路径在 android/app/build.gradle 添加:compile project(':react-native-vector-icons')
apply plugin: 'com.android.application'android {  ...}dependencies {  compile fileTree(dir: 'libs', include: ['*.jar'])  compile "com.android.support:appcompat-v7:23.0.1"  compile "com.facebook.react:react-native:+"  // From node_modules  ....  compile project(':react-native-vector-icons')}
最后一步:在android/app/src/main/java/你的包/MainApplication.java中添加
 
import com.oblador.vectoricons.VectorIconsPackage;new VectorIconsPackage()
代码如下:
package com.myapp;import com.oblador.vectoricons.VectorIconsPackage;....  @Override  protected List getPackages() {    return Arrays.asList(      new MainReactPackage() , new VectorIconsPackage()    );  }}
 

然后在此运行项目即可。

测试代码:

import React, {  Component} from 'react';import {  Platform,  StyleSheet,  Text,  View} from 'react-native';import Icon from 'react-native-vector-icons/FontAwesome';const instructions = Platform.select({  ios: 'Press Cmd+R to reload,\n' +    'Cmd+D or shake for dev menu',  android: 'Double tap R on your keyboard to reload,\n' +    'Shake or press menu button for dev menu',});type Props = {};export default class App extends Component < Props > {  render() {    return (                                            Welcome to React Native!                          To get started, edit App.js                          {instructions}                  );  }}const styles = StyleSheet.create({  container: {    flex: 1,    justifyContent: 'center',    alignItems: 'center',    backgroundColor: '#F5FCFF',  },  welcome: {    fontSize: 20,    textAlign: 'center',    margin: 10,  },  instructions: {    textAlign: 'center',    color: '#333333',    marginBottom: 5,  },});
react-native-vector-icons(android)的安装与使用_第1张图片


更多相关文章

  1. Android 入门第八讲02-WebView的高级用法(Android调用 JS 代码( lo
  2. 在eclipse中查看android SDK的源代码
  3. Android彻底组件化—代码和资源隔离
  4. 获取Android的Java源代码并在Eclipse中关联查看的最新方法
  5. 在代码中实现android:tint效果
  6. 【Android 开发】: Android 消息处理机制之二: Message 中 obtai
  7. android 网络访问-图片处理优秀开源项目
  8. pandaboard ES学习之旅——4 Android源代码下载与编译
  9. 【Android每日一练】Android项目结构详解

随机推荐

  1. 浅析Android如何从不同的层次保证安全性
  2. Retrofit系列文章翻译2—Android上的基本
  3. Android的Log系统
  4. Android:Android学习进阶路线
  5. Android(安卓)WebView 获取html iframe内
  6. Android入门教程(三十一)------SQLite分
  7. Android(安卓)UI设计——ListView控件和A
  8. Android周学习Step By Step(6)--Android的
  9. Android(安卓)Drawable Resource学习(一)、
  10. Android(安卓)AsyncTask