Android Emulator API 26 does not display adaptive icon - android

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

Related

Adaptive icons not working in Oreo - why?

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.

app launcher icon changed to default icon on Oreo

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.

Change the color of the icon vs make icons in many color

I am confused between changing the color of the icon at run time using:
Drawable x = getResources().getDrawable(R.drawable.ic_action_xx);
x.setColorFilter(Color.parseColor("#000000"), PorterDuff.Mode.SRC_ATOP);
or creating many icons files in each color that I need !
Any help ! THANK YOU
It depends on an amount of pictures. I would create images for each if there are only a few colors (White and Black for example). But for hundreds of colors, I think it's better to use a filter.
Actually, if you app support only SDK version > lollipop
you can you use tint parameter in xml.
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/ic_back"
android:tint="#color/red_tint"/>
Install MaterialDesignIconGeneratorPlugin following this link
https://github.com/konifar/android-material-design-icon-generator-plugin

ResXMLTree_node header size 0x0 is too small in Android Menu

I'm currently setting up an app and stumbled upon some error which I don't understand.
I have a menu XML and provide here two icons.
For the menu in the top right, I want to stick to the standard and use the three vertical dots which go by this name:
ic_menu_moreoverflow_normal_holo_light
Unfortunately though, I get this error:
W/ResourceType(11504): ResXMLTree_node header size 0x0 is too small.
... and my R won't compile anymore.
However It works, for example with
ic_menu_info_details
or
ic_menu_search
Copying the icon itself in drawables didn't work either (?)
Does anyone have an explanation? The exisiting questions don't refer to this.
Here is the full code:
<item
android:id="#+id/menu_send"
android:icon="#android:drawable/ic_menu_info_details"
android:showAsAction="ifRoom|withText"
android:title="Options"/>
The error comes, when I try to incorporate it like:
<item
android:id="#+id/menu_send"
android:icon="#android:drawable/ic_menu_moreoverflow_normal_holo_light"
android:showAsAction="ifRoom|withText"
android:title="Options"/>
Cleaning the code yields that R won't compile anymore.
I just would like to understand, maybe this icon doesn't exist? I googled it though.
After asking google i've found this:
It appears to be that this particular icon wasn't available pre Honeycomb (API 11). I am guessing that you may be getting this error because you're targetting the application to be supported pre-Honeycomb.
Can you try setting this on your manifest.xml:
<manifest>
<uses-sdk android:minSdkVersion="11" />
...
</manifest>

How to display custom font correctly with utf-8 character on android 2.3

I have use custom font(Trebuchet Ms, Georgia,..) in my android app. It displays utf-8 characters correctly in android 4.0, but in android 2.3 it will display wrong character.
Anyone has experiance with this problem. I have researched but find out nothing.
Check in the AndroidManifest.xml that you have this at first line:
<?xml version="1.0" encoding="utf-8"?>

Categories

Resources