无法更改Android应用程序的默认图标?

4
我遇到了一个问题。我使用phonegap、cordova和eclipse将JavaScript应用程序转换为Android应用程序。应用程序运行良好。
但问题是,它总是显示cordova图标作为应用程序图标。我替换了"project/res"文件夹中的所有图标。但仍然只显示默认图标?
我通过谷歌搜索得知我必须在清单文件中进行更改。所以,我在AndroidManifest.XML中进行了更改,代码如下:
android:icon="@drawable/icon"

"icon" 是我的图片名称。

这里有什么问题?为什么我没有得到自己的图标?我是 Android 环境的新手。

我按照这篇文章 http://smartgap.wordpress.com/2012/08/11/customizing-launch-icon-on-eclipsephonegap-application/ 进行操作。

我的 Manifest 文件:

<?xml version="1.0" encoding="utf-8"?>
<!--
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:windowSoftInputMode="adjustPan"
      package="com.mage.edunxt" android:versionName="1.0" android:versionCode="1" android:hardwareAccelerated="true">
    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true"
        android:resizeable="true"
        android:anyDensity="true"
        />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.RECORD_VIDEO"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />   
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />   
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />

    <application android:icon="@drawable/icon" android:label="@string/app_name"
        android:hardwareAccelerated="true"
        android:debuggable="true">
        <activity android:name="EduNxtQTIPlayer" android:label="@string/app_name"
                android:theme="@android:style/Theme.Black.NoTitleBar"
                android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/>
</manifest> 

你从所有的drawable文件夹中删除了默认图标吗?尝试卸载应用并重新安装。此外,有可能你使用了一些不免费或需要使用其图标的许可证工具。因此,它们可能会通过编程方式设置图标。 - dcow
@DavidCowden 我没有删除旧图标。但我将其重命名了。此外,我卸载并重新安装了应用程序,但是没有用。那么这不是任何工具的图标。这是我的自定义图标。我只想将其用于我的应用程序。 - Edwin Alex
@g00dy非常抱歉给你带来了不便。我把我的图标放在“res”文件夹里。现在已经有一个cordova图标在显示。我将这个cordova图标重命名为另一个名称,然后用“icon”这个名称保留了我的图标。 - Edwin Alex
@g00dy 实际上我现在正在做你最初建议的那个。但是没有用处。我认为它从你的观点来看是从另一个地方获取的。 - Edwin Alex
你改变了每个文件夹中的可绘制图标(也就是用你自己的替换了默认的),这些文件夹实际上对应于你设备的分辨率和像素密度吗? - g00dy
显示剩余16条评论
6个回答

7
我必须执行以下操作:
  1. 将所有文件添加到我的res / Drawables文件夹中
  2. 在manifest.xml中的活动上设置图标属性。它让我选择浏览在我的Drawable目录中设置的文件。
  3. 我必须进行清理才能使其正常工作。

清除似乎非常重要,直到你清理为止仍将使用旧的图标。

在Eclipse中,选择项目->清理。


1
“Clean”是什么意思?你指的是哪个命令/选项/菜单? - Xosofox
1
清理是关键。 - asp_net

5

我通过以下方式解决了问题。

我将我的图标放在"project/bin/res"文件夹中的所有文件夹中。

然后,在"project/res/xml"下的config.xml中添加了以下行。

<icon src="icon.png" /> 

现在它正在很酷地工作。


更多详细信息请参阅Apache Cordova文档。https://cordova.apache.org/docs/en/latest/config_ref/images.html - anirus

2
我一直在使用Phonegap CLI进行本地构建,没有使用Eclipse,在查看根文件夹时遇到了多个问题(对于本地构建来说是无用的... Phonegap:构建时可以输出一些注释吗)。
最终,我将不同尺寸的图标文件复制到了drawable*文件夹中。
drawable-hdpi drawable-ldpi drawable-mdpi drawable-xhdpi
这浪费了我很多时间。

0

我也想分享一下我的答案,以防他们无法使用之前用户提供的步骤使其正常工作。

我无法使用此处提供的步骤使我的工作正常,并且我能够通过使用 mipmaps 找出问题所在。我使用了这个开源项目生成图标大小,非常好用:Android Asset Studio

我现在注意到生成的图标现在放置在 mipmap 文件夹中而不是 drawable 中。我认为这就是 Google 希望我们将 drawable 与图标分开的方式。做完这些后,我使用以下方法引用新导入的 mipmap 文件夹:

 android:icon="@mipmap/ic_launcher"

这里是文件夹结构:

res/
    mipmap-mdpi/ic_launcher.png (48x48 pixels)
    mipmap-hdpi/ic_launcher.png (72x72)
    mipmap-xhdpi/ic_launcher.png (96x96)
    mipmap-xxhdpi/ic_launcher.png (144x144)
    mipmap-xxxhdpi/ic_launcher.png (192x192)

我清理并重新构建了项目,现在我可以看到图标了!但是有一个问题。它是在较新版本的Android(如此处所述link)中添加的。关于这一点没有太多的文档,不确定它是否适用于旧版本的Android。


0

PhoneGap网页上提供的信息解释了这一点,但可能一开始并不是很清楚(链接:http://docs.build.phonegap.com/en_US/configuring_icons_and_splash.md.html#_icons)。

简单的解释:只需将您的图标复制到应用程序根目录并将其命名为icon.png。这就是你所需要的全部。

在我的情况下,我确保图标的大小为96x96像素(更大的某种程度上不起作用,但可能是我的问题)。而且,在上传和重建后,应用程序内容没有更新 - 所以我需要重复上传+重建几次。


0

在<项目位置>\platforms\android\res中进行更改是无效的,应该在<项目位置>\platforms\android\ant-build\res中进行更改。

对于某些人来说,在后者位置进行更改可能有效,但我注意到Phonegap会将\android\res中的内容复制到\android\ant-build\res中,因此我决定在那里进行检查,并找到了一个包含默认phonegap图标的单独的drawable文件夹集合。

最终更改那些文件才奏效。

由于我正在本地构建和运行,而不是使用Adobe PhoneGap Build,因此在<项目位置>\www\res\icon\android中更改图标也不起作用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接