【问题标题】:Unable to change icon in phonegap apps无法更改 phonegap 应用程序中的图标
【发布时间】:2017-01-31 23:59:58
【问题描述】:

我正在尝试使用 PhoneGap 开发一个 Android 应用程序。我想更改应用程序图标和启动画面图像,它们始终是这个默认的怪羊:

https://i.stack.imgur.com/DLNLs.png

到目前为止,我所做的是更改根文件夹“AppName”中的文件“icon.png”,并替换了AppName\www\res\icon\androidAppName\www\res\screen\android 的所有图像,但它总是看起来一样默认图片。

你能帮帮我吗?

config.xml的代码

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.helloworld" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>AppName</name>
    <description>
        App description.
    </description>
    <author email="my@mail.com" href="http://www.website.com">
        S. B.
    </author>
    <content src="index.html" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="android-minSdkVersion" value="14" />
    <plugin name="cordova-plugin-battery-status" source="npm" spec="~1.1.1" />
    <plugin name="cordova-plugin-camera" source="npm" spec="~2.1.1" />
    <plugin name="cordova-plugin-media-capture" source="npm" spec="~1.2.0" />
    <plugin name="cordova-plugin-console" source="npm" spec="~1.0.2" />
    <plugin name="cordova-plugin-contacts" source="npm" spec="~2.0.1" />
    <plugin name="cordova-plugin-device" source="npm" spec="~1.1.1" />
    <plugin name="cordova-plugin-device-motion" source="npm" spec="~1.2.0" />
    <plugin name="cordova-plugin-device-orientation" source="npm" spec="~1.0.2" />
    <plugin name="cordova-plugin-dialogs" source="npm" spec="~1.2.0" />
    <plugin name="cordova-plugin-file" source="npm" spec="~4.1.1" />
    <plugin name="cordova-plugin-file-transfer" source="npm" spec="~1.5.0" />
    <plugin name="cordova-plugin-geolocation" source="npm" spec="~2.1.0" />
    <plugin name="cordova-plugin-globalization" source="npm" spec="~1.0.3" />
    <plugin name="cordova-plugin-inappbrowser" source="npm" spec="~1.3.0" />
    <plugin name="cordova-plugin-media" source="npm" spec="~2.2.0" />
    <plugin name="cordova-plugin-network-information" source="npm" spec="~1.2.0" />
    <plugin name="cordova-plugin-splashscreen" source="npm" spec="~3.2.1" />
    <plugin name="cordova-plugin-statusbar" source="npm" spec="~2.1.2" />
    <plugin name="cordova-plugin-vibration" source="npm" spec="~2.1.0" />
    <plugin name="cordova-plugin-whitelist" source="npm" spec="~1.2.1" />
    <icon src="icon.png" />
    <platform name="android">
        <icon density="ldpi" src="www/res/icon/android/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="www/res/icon/android/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="www/res/icon/android/drawable-hdpi-icon.png" />
        <icon density="xhdpi" src="www/res/icon/android/drawable-xhdpi-icon.png" />
        <icon density="xxhdpi" src="www/res/icon/android/drawable-xxhdpi-icon.png" />
        <icon density="xxxhdpi" src="www/res/icon/android/drawable-xxxhdpi-icon.png" />
        <splash density="land-ldpi" src="www/res/screen/android/drawable-land-ldpi-screen.png" />
        <splash density="land-mdpi" src="www/res/screen/android/drawable-land-mdpi-screen.png" />
        <splash density="land-hdpi" src="www/res/screen/android/drawable-land-hdpi-screen.png" />
        <splash density="land-xhdpi" src="www/res/screen/android/drawable-land-xhdpi-screen.png" />
        <splash density="land-xxhdpi" src="www/res/screen/android/drawable-land-xxhdpi-screen.png" />
        <splash density="land-xxxhdpi" src="www/res/screen/android/drawable-land-xxxhdpi-screen.png" />
        <splash density="port-ldpi" src="www/res/screen/android/drawable-port-ldpi-screen.png" />
        <splash density="port-mdpi" src="www/res/screen/android/drawable-port-mdpi-screen.png" />
        <splash density="port-hdpi" src="www/res/screen/android/drawable-port-hdpi-screen.png" />
        <splash density="port-xhdpi" src="www/res/screen/android/drawable-port-xhdpi-screen.png" />
        <splash density="port-xxhdpi" src="www/res/screen/android/drawable-port-xxhdpi-screen.png" />
        <splash density="port-xxxhdpi" src="www/res/screen/android/drawable-port-xxxhdpi-screen.png" />
    </platform>
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <engine name="android" spec="~6.0.0" />
</widget>

【问题讨论】:

    标签: android cordova


    【解决方案1】:

    对我来说,它可以更改 \platforms\android\res\mipmap 中的图像。在那里,我更改了所有分辨率的图像。

    【讨论】:

    • 谢谢,威廉。我或多或少地这样做了,但有时有效,有时无效。我所做的是使用“phonegap build android”,然后替换“AppName\platforms\android\res\”中的文件。但是,如果我想再次更改它们,我必须重复该过程并确保它们已在“AppName\platforms\android\build\intermediates\res\merged\debug”中更改。如果没有,我必须从“AppName\platforms\android\res\”中删除文件,输入“phonegap build android”,再次创建文件并重新输入“phonegap build android”。看起来很奇怪,但它确实有效。再次感谢!
    • 是的,这很奇怪。我现在想知道什么可以解决这个问题
    【解决方案2】:

    最好在配置文件中指定不同的路径存储该路径中所有需要的图像。您可以使用cordova插件实现。

    参考:https://cordova.apache.org/docs/en/latest/config_ref/images.html

    <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>
    

    使用cordova闪屏插件 // npm 托管(新)id 科尔多瓦插件添加科尔多瓦插件闪屏

    // 你也可以直接从这个 repo 安装 科尔多瓦插件添加https://github.com/apache/cordova-plugin-splashscreen.git

    参考:https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-splashscreen/

    【讨论】:

      【解决方案3】:

      关注这个官方文档Phonegap Docs - Icons and Splash

      【讨论】:

        猜你喜欢
        • 2016-05-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多