我正在做一个React Native应用程序。我想自定义应用程序图标(意味着你点击启动应用程序的图标)。我在谷歌上搜索过,但我一直在寻找不同类型的图标,它们指的是不同的东西。如何将这些类型的图标添加到应用程序中?


当前回答

有人专门为这项任务制作了一个非常容易使用的工具:https://www.npmjs.com/package/app-icon

这个简单的工具允许您在react-native项目中创建单个图标,然后从它创建所有所需大小的图标。它目前适用于iOS和Android。

我用过。制作一个512x512的png文件,然后运行该工具,完成。超级简单。

其他回答

有人专门为这项任务制作了一个非常容易使用的工具:https://www.npmjs.com/package/app-icon

这个简单的工具允许您在react-native项目中创建单个图标,然后从它创建所有所需大小的图标。它目前适用于iOS和Android。

我用过。制作一个512x512的png文件,然后运行该工具,完成。超级简单。

iOS图标

在Images.xcassets中设置AppIcon。 添加9个不同大小的图标: 29 pt 29 pt * 2 29 pt * 3 40 pt * 2 40 pt * 3 57分 57 pt * 2 60 pt * 2 60 pt * 3。

图像。Xcassets看起来是这样的:

Android图标

将ic_launcher.png放入[ProjectDirectory]/android/app/src/main/res/mipmap-*/文件夹中。 mimmap -hdpi中的72*72 ic_launcher.png。 mimmap -mdpi中的48*48 ic_launcher.png。 mimmap -xhdpi中的96*96 ic_launcher.png。 144*144 ic_launcher.png mimmap -xxhdpi。 mimmap -xxxhdpi中的192*192 ic_launcher.png。

2019年更新

react native的最新版本也支持圆形图标。对于这种特殊情况,您有两个选择:

A.添加圆形图标: 在每个mipmap文件夹中,在ic_launcher.png文件中添加一个同样大小的圆形版本,称为ic_launcher_round.png。

B.移除圆形图标: 在你的projectfolder /android/app/src/main/AndroidManifest.xml中删除一行android:roundIcon="@mipmap/ic_launcher_round"并保存它。

否则构建将抛出错误。

在React-Native项目中为Android设备设置应用程序启动图标:

Take a high resolution image of your logo and place it inside your project directory. Preferably in [Project-DIR]/android/app/src/main/res/ Open Android Studio and run your React-native project. In Android Studio's Project window, select the Android view Right-click the res folder and select New > Image Asset A "Configure Image Asset" window will open; Locate your high resolution image and place set it as your "Foreground layer". Set your "Background Layer" if applicable Click "Next" and continue to finish. Run your application again to see the new app launch icon.

官方文档可以在这里找到:https://developer.android.com/studio/write/image-asset-studio

你可以导入react-native-elements,并在你的react native应用程序中使用font-awesome图标

安装

npm install --save react-native-elements

然后把它导入到你想要使用图标的地方

import { Icon } from 'react-native-elements'

像这样使用它

render() {
   return(
    <Icon
      reverse
      name='ios-american-football'
      type='ionicon'
      color='#517fa4'
    />
 );
}

我遵循了他的建议并使用android Asset Studio在react-native android项目中添加了应用图标

以下是为防止链接失效而转录的内容:

如何在React-Native Android上传应用程序图标

1)上传你的图像到Android Asset Studio。 选择任何你想应用的效果。该工具为您生成一个zip文件。点击下载。zip。

2)在你的机器上解压缩文件。然后拖动你想要的图片到你的/android/app/src/main/res/文件夹。确保将每个图像放在正确的子文件夹mipmap-{hdpi, mdpi, xhdpi, xxhdpi, xxxhdpi}。

3)不要(像我最初做的那样)天真地将整个文件夹拖放到你的res文件夹上。因为你可能会删除你的/res/values/{strings,styles}.xml文件。