简体   繁体   English

如何使用适用于Android和iOS的Cordova为应用设置图标

[英]How to set Icon for app using Cordova for Android and iOS

我使用适用于Android的Cordova Phonegap构建了一个应用程序,但对于如何为我的应用程序设置应用程序图标感到困惑,以便它既应支持Android也应支持iOS。

You can configure this using the <icon> element in config.xml which is the main Cordova configuration file for your project. 您可以使用config.xml<icon>元素进行配置,该元素是项目的主要Cordova配置文件。 You will need your icons in a range of sizes for the different platforms that you are targeting. 您需要针对不同目标平台使用各种尺寸的图标。

Example config.xml entry for Android: 适用于Android的示例config.xml条目:

<platform name="android">
    <!--
        ldpi    : 36x36 px
        mdpi    : 48x48 px
        hdpi    : 72x72 px
        xhdpi   : 96x96 px
        xxhdpi  : 144x144 px
        xxxhdpi : 192x192 px
    -->
    <icon src="res/android/ldpi.png" density="ldpi" />
    <icon src="res/android/mdpi.png" density="mdpi" />
    <icon src="res/android/hdpi.png" density="hdpi" />
    <icon src="res/android/xhdpi.png" density="xhdpi" />
    <icon src="res/android/xxhdpi.png" density="xxhdpi" />
    <icon src="res/android/xxxhdpi.png" density="xxxhdpi" />
</platform>

and for iOS: 对于iOS:

<platform name="ios">
    <!-- iOS 8.0+ -->
    <!-- iPhone 6 Plus  -->
    <icon src="res/ios/icon-60@3x.png" width="180" height="180" />
    <!-- iOS 7.0+ -->
    <!-- iPhone / iPod Touch  -->
    <icon src="res/ios/icon-60.png" width="60" height="60" />
    <icon src="res/ios/icon-60@2x.png" width="120" height="120" />
    <!-- iPad -->
    <icon src="res/ios/icon-76.png" width="76" height="76" />
    <icon src="res/ios/icon-76@2x.png" width="152" height="152" />
    <!-- Spotlight Icon -->
    <icon src="res/ios/icon-40.png" width="40" height="40" />
    <icon src="res/ios/icon-40@2x.png" width="80" height="80" />
    <!-- iOS 6.1 -->
    <!-- iPhone / iPod Touch -->
    <icon src="res/ios/icon.png" width="57" height="57" />
    <icon src="res/ios/icon@2x.png" width="114" height="114" />
    <!-- iPad -->
    <icon src="res/ios/icon-72.png" width="72" height="72" />
    <icon src="res/ios/icon-72@2x.png" width="144" height="144" />
    <!-- iPhone Spotlight and Settings Icon -->
    <icon src="res/ios/icon-small.png" width="29" height="29" />
    <icon src="res/ios/icon-small@2x.png" width="58" height="58" />
    <!-- iPad Spotlight and Settings Icon -->
    <icon src="res/ios/icon-50.png" width="50" height="50" />
    <icon src="res/ios/icon-50@2x.png" width="100" height="100" />
    <!-- iPad Pro -->
    <icon src="res/ios/icon-83.5@2x.png" width="167" height="167" />
</platform>

You will need to set src to the appropriate relative path to where you are storing your icons in your project... res/<platform_name>/... would be a good path to use but you can use anything. 您需要将src设置为在项目中存储图标的适当相对路径... res/<platform_name>/...将是一个很好的使用路径,但您可以使用任何东西。

Further information can be found in the official Cordova documentation . 可以在Cordova官方文档中找到更多信息。

paste your icon in res->icon->android = if android then paste in android,if ios than ios. 将您的图标粘贴到res-> icon-> android =如果android然后粘贴到android,如果ios比ios。 than after open main config file of cordova project. 比在打开cordova项目的主配置文件之后。 it will look like below : 它将如下所示:

<platform name="android">
    <allow-intent href="market:*" />
    <icon density="ldpi" src="res/icon/android/user.png" />
    <icon density="mdpi" src="res/icon/android/user.png" />
    <icon density="hdpi" src="res/icon/android/user.png" />
    <icon density="xhdpi" src="res/icon/android/user.png" />
</platform>

Also ensure that the platform being targeted is that your intended platform using the config-file tag. 还要确保目标平台是使用config-file标记的目标平台。

Example: 例:

<gap:config-file platform="android">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM