【问题标题】:Question mark is appeared as icon in react native application问号在反应本机应用程序中显示为图标
【发布时间】:2020-01-10 09:10:48
【问题描述】:

我正在尝试在我的 react native 项目中使用 Icon,所以我安装了:

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

2.react-native link react-native-vector-icons

这部分之后的所有图标都添加到android/app/sec/main/assets/fonts:

ls -l /media/groot/Project/React\ Native/Practices/RNheader/android/app/src/main/assets/fonts
total 1976
-rwxrwxrwx 1 groot groot  70344 Jan  9 16:45 AntDesign.ttf
-rwxrwxrwx 1 groot groot  65584 Jan  9 16:45 Entypo.ttf
-rwxrwxrwx 1 groot groot  13456 Jan  9 16:45 EvilIcons.ttf
-rwxrwxrwx 1 groot groot  58272 Jan  9 16:45 Feather.ttf
-rwxrwxrwx 1 groot groot 125016 Jan  9 16:45 FontAwesome5_Brands.ttf
-rwxrwxrwx 1 groot groot  34092 Jan  9 16:45 FontAwesome5_Regular.ttf
-rwxrwxrwx 1 groot groot 186228 Jan  9 16:45 FontAwesome5_Solid.ttf
-rwxrwxrwx 1 groot groot 165548 Jan  9 16:45 FontAwesome.ttf
-rwxrwxrwx 1 groot groot 313528 Jan  9 16:45 Fontisto.ttf
-rwxrwxrwx 1 groot groot  56976 Jan  9 16:45 Foundation.ttf
-rwxrwxrwx 1 groot groot 112472 Jan  9 16:45 Ionicons.ttf
-rwxrwxrwx 1 groot groot 546548 Jan  9 16:45 MaterialCommunityIcons.ttf
-rwxrwxrwx 1 groot groot 128180 Jan  9 16:45 MaterialIcons.ttf
-rwxrwxrwx 1 groot groot  28364 Jan  9 16:45 Octicons.ttf
-rwxrwxrwx 1 groot groot  54056 Jan  9 16:45 SimpleLineIcons.ttf
-rwxrwxrwx 1 groot groot  25552 Jan  9 16:45 Zocial.ttf
  1. 我这样添加到我的 js 文件中:

    从“react-native-vector-icons/Ionicons”导入图标;

这是我的文件:

import React from 'react';
import { View, Text, Button, StyleSheet } from 'react-native';
import Icon from "react-native-vector-icons/Ionicons";


export default HeaderView = () => {
    return (
        <View style={styles.headerStyle} >
            <View style={styles.columnStyle}>
                <Icon name="arrow-back" size={15}/>

            </View>
            <Text>Test</Text>
        </View>)
}

但是当我在 android 模拟器上运行项目时,图标显示为 ?

我收到了这个警告:

那是我的错?

我想我添加了正确的图标名称:

【问题讨论】:

    标签: android react-native react-native-android


    【解决方案1】:

    您需要使用md-arrow-back 而不是arrow-back

    原因如 Iconicons 网站所述,

    在没有 Ionic 框架的情况下使用 Ionicons 时,图标将默认 到 Material Design 图标样式。指定非默认图标 样式,为 name 属性添加平台前缀。

    这意味着如果您不在 ionic 框架中使用它,则必须在任何图标名称之前添加前缀 md

    您可以在usage pageIconicons 中查看更多信息。

    【讨论】:

      【解决方案2】:

      这意味着您提供的名称 arrow-back 对该图标无效,请将 name="arrow-back" 更改为 name="md-arrow-back"。如果您真的想使用 arrow-backMaterialIcons 导入而不是 Ionicons

      【讨论】:

      • 谢谢兄弟。它的工作,但在它的网站上,我在分配为“箭头”的图标名称上方添加了..为什么?我用Ionicons不是MaterialIconsimport Icon from "react-native-vector-icons/Ionicons";@TebogoMahlalela
      • 不知道为什么它会在本周早些时候发生在我身上,然后我从另一个目录导入并且它起作用了。但是在您的情况下,它显示了黄色框,这意味着问题出在名称上。
      • 你不知道我怎么用Ionicons
      • 只要确保您的图标名称与网站 Ionicons 目录下的任何名称匹配
      • 好的,伙计。看上面的图片,我使用来自 Ionicons 的arrow-back,但出现错误?“箭头后退”图标的确切名称是什么?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-27
      • 2021-02-06
      • 1970-01-01
      相关资源
      最近更新 更多