如何使用带有 react-native-vector-icons 的材料社区图标

新手上路,请多包涵

我正在尝试在材料社区图标中使用店面图标。但是我得到一个错误,它不显示图标。这是我的代码:

 import { StatusBar } from "expo-status-bar";
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import { createMaterialBottomTabNavigator } from "@react-navigation/material-bottom-tabs";
import { NavigationContainer } from "@react-navigation/native";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";

import Products from "./src/components/Products";
import Cart from "./src/components/Cart";
import Account from "./src/components/Account";

const Tab = createMaterialBottomTabNavigator();

export default class App extends React.Component {
  render() {
    return (
      <NavigationContainer>
        <Tab.Navigator
          initialRouteName="Browse"
          activeColor="#f0edf6"
          inactiveColor="#A3A3A3"
          barStyle={{ backgroundColor: "#515151" }}
        >
          <Tab.Screen
            name="Browse"
            component={Products}
            options={{
              tabBarLabel: "Browse",
              tabBarIcon: ({ color }) => (
                <Icon name="storefront-outline" color={color} size={26} />
              ),
            }}
          />
          <Tab.Screen name="Cart" component={Cart} />
          <Tab.Screen name="My Account" component={Account} />
        </Tab.Navigator>
      </NavigationContainer>
    );
  }
}

我已经安装了 Ionic 的矢量图标库和其他图标,用于示例工作。

编辑:

我想我需要将 react-native 链接到 react-native-vector-icons 但我收到一条错误消息 The term 'react-native' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

编辑 2:我认为这只是我无法访问的一些 Material Community 图标,包括“storefront-outline”和“store-front”。也许它们已被弃用但在您搜索商店时仍然存在?感谢大家的帮助,但我会根据我的情况使用替代图标,因为我已经阅读了矢量图标文档中的所有词干。

原文由 anonymous 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 458
1 个回答

按照以下步骤 -

步骤 - 1:导入图标系列

import { MaterialCommunityIcons } from '@expo/vector-icons';

步骤 - 2:渲染组件

<MaterialCommunityIcons name="access-point" size={24} color="black" />

原文由 Rakesh Medpalli 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题