I'm trying to add a custom icon from an SVG file to my Android app by right-clicking on the res folder -> new -> Image asset. I have selected the default options, using my SVG but I can't see the icon when I'm running the app.
I have tried to do a clean project before installing it and also an invalidate cache and restart and the result is the same.
I've also realized that mipmap-anydpi-v26/ic_launcher.xml shows the default icon I'm seeing when my app is installed. This file contains:
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="#drawable/ic_launcher_background"/>
<foreground android:drawable="#drawable/ic_launcher_foreground"/>
</adaptive-icon>
when clicking on the #drawable/ic_launcher_foreground I get to locations to open: drawable and drawable-24. The first one shows my recently updated icon, but drawable-24 shows the default Android icon I see when installing my app.
Is there anything I'm missing here? Anything else I have to do?
Thanks!
drawable-24 folder has higher priority than drawable.
Api-specific resources, along with resolution-specific and language-specific are always more preferrable by Android than unspecified resources.
Well, in the end, I just created the icons from a PNG instead an SVG and it works great.
Related
I have made a new project in the android studio, and this error shows up. I have clean and rebuild the project but this error is not resolving.
Colors.xml default coding is missing and this auto-generated text is showing.
I solved this problem as shown in the image below:
The first image(Error)
Error Image
Solution:
Go to your user folder:
User Folder
I deleted these two files (.AndroidStudio3.4) and (.gradle).
note/Android will download it automatically
The encoding in your XML and XSD (or DTD) are different.
XML file header: <?xml version='1.0' encoding='utf-8'?>
XSD file header: <?xml version='1.0' encoding='utf-16'?>
Another possible scenario that causes this is when anything comes before the XML document type declaration. i.e you might have something like this in the buffer:
helloworld<?xml version="1.0" encoding="utf-8"?>
or even a space or special character.
There are some special characters called byte order markers that could be in the buffer.
Before passing the buffer to the Parser do this...
String xml = "<?xml ...";
xml = xml.trim().replaceFirst("^([\\W]+)<","<");
The "content not allowed in prolog" is actually an error from XML parser. It means that an XML document was expected, but something else has been received.
colors file is an resource file , you can put your resources under tag.
You can not put contain in this file like you have done there.
Following is example you can use to understand
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorBlue">#000099</color>
<color name="colorRed">#ff0015</color>
</resources>
Notice the error is:
content is not allowed in prolog
The colors.xml file's format should be completely correct, for example:
item<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
</resources>
will cause this error because of item misplaced before <?xml version="1.0" encoding="utf-8"?>
After installing Android Studio (3.5.3) and creating my first Hello Android project, things were smooth and the app ran perfectly fine and I was able to make modification and view them on the Emulator.
However, after few days, I decided to create a new module under the same project or even tried to create a new Android project, I started facing the same issue as yours where it was showing that “Error: Content is not allowed in prolog.” and it was pointing to colors.xml. Nevertheless, when I ran Gradle analysis (Gradle Scripts --> Analyze --> Inspect Code) it showed that most *.xml files in the new project are having same issue. If you open the xml files, it will look sort of corrupted but for some reason, the code got encrypted.
The workaround that really worked for me was replacing the corrupted/encrypted code with the one that I had from my first working project. I build the app and it runs perfectly fine.
The xml files that I had to revisit were:
- colors.xml
- ic_launcher_foreground.xml
- ic_launcher_background.xml
- ic_launcher_round.xml
- ic_launcher.xml
This might not be the best solution, but it really worked out for me
I solved it by deleting the colors.xml file and pasting a colors.xml from another project. It will work well unless you modify your original colors file in this case you need to rewrite it.
Was facing the same issue. Delete or modify all the xml with the resources names what you are using as references. It will work.
I have created an Android app with its own launcher icon. It worked well with Nougat. But with Oreo, my icon is replaced by the default Android icon.
I have defined ic_launcher.png and ic_launcher_round.png in the mipmap resources for several densities.
My manifest contains the following line:
android:roundIcon="#mipmap/ic_launcher_round"
What should I do to make my own icon appear on Oreo ?
For API 26+ default Android application template defines another icon resource folder
mipmap-anydpi-v26
That folder (usually) contains two xml files ic_launcher and ic_launcher_round that match icon resources declared in manifest for API 26+
Content of those files looks like following:
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="#drawable/ic_launcher_background"/>
<foreground android:drawable="#drawable/ic_launcher_foreground"/>
</adaptive-icon>
In order to have your icon you also need to change all drawables (in all density buckets) listed there - namely ic_launcher_background and ic_launcher_foreground
Or you can just delete that folder, in which case android will fallback to using your png icons, but they will not appear as-is and will be commonly drawn on top of white background.
You can read more at: Adaptive icons
Best solution is delete mipmap-anydpi-v26 folder then app will take default icon. In android studio Project mode go to this package
res/mipmap-anydpi-v26
delete it and rebuild and Run Project.
My solution:
check res/mipmap-anydpi-v26 folder, then you will see ic_launcher.xml and ic_launcher_round.xml files
edit these xml files to point to the actual png file you want to use:
If such png file is not available inside the drawable folder, add it.
That solves the issue.
I am trying to change launcher icon for the application I am developing but the icon remains same (Android Studio 3.0). I have tried changing it from manifest.xml and minimap. It appears to be picking up icon from two XML files named as ic_launcher_background.xml and ic_launcher_forground.xml. I have tried deleting these files but safe delete is not allowing me to. I am attaching screenshot of my project.
enter image description here
try to move your your ic_launcher_torch icon into mipmap directory
Remove the ic_launcher_torch.png file from drawables folder.
Right click on res folder> New Image Asset > Icon type > Action Bar and Tab Icons > Asset type - image > Choose your logo in path > finish.
Add android:icon="#mipmap/yourLogoName"
The image will be saved in /res/drawable folder. Learn more: https://developer.android.com/studio/write/image-asset-studio.html
Copy & paste launcher icon .png file to mipmap folder. Better if you add icon to all screen types hdpi, mdpi, xhdpi & etc. Then change android manifest code like this.
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
make changes in manifest file at both location
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
First uninstall the app from the phone(dont reinstall when you already have it installed)
After the app is uninstalled ,try installing it once again .
I had the same issue ,wasted around 2 hrs and this worked for me
Android O introduced adaptive icons, so I went ahead and tried to implement it. Using AS 3.0, I've followed the steps and created the mipmap-anydpi-v26 directory, and within it a ic_launcher.xml
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="#mipmap/ic_background"/>
<foreground android:drawable="#mipmap/ic_foreground"/>
</adaptive-icon>
I'm running a Pixel emulator running Android O, but for some reason it's simply showing what appears to be the default icon (green background with android logo on top).
If I change the icon back to my legacy icon, it works flawlessly.
Am I missing some here, or is this some kind of emulator issue?
According to the official documentation ic_launcher.xml should be placed in res/mipmap-anydpi without specifying -v26 at the end. Also check the icon size and a simpler icon e.g. with background as a color (<background android:drawable="#color/ic_background"/>)
Have you tried that?
Had the same issue. Switching to buildTools 26 solved it for me.
Edit: I see casolorz has already answered the same thing
Is it possible to change the icon of my android application only in the applications manager (Settings->manage applications) to be something other than the app icon (Launcher)?
I use android:icon in the AndroidManifest but it changes the twice. I honestly can't find any answer to this.
By Settings->manage applications, if you mean Device Setting Account manager icon, then in your application res folder you can find xml folder, from the xml file on that folder you need to change your icon.
For example --
<account-authenticator
xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="#string/auth_type"
android:icon="#drawable/ic_contest_icon"
android:label="#string/app_name"
android:smallIcon="#drawable/ic_contest_icon" />
you need to put your icon id from drawable on android:icon="#drawable/ic_contest_icon"
and android:smallIcon="#drawable/ic_contest_icon"