Transparent responsive icon background

So, I have been working on this application for a couple of weeks, and I started to create an icon. I have Android Studio 3.0.1, and they seem to have changed the way they create the image, now they have responsive icons. I made an icon with a transparent background for my application. Previously, I would just change the shape to "none" and the background would not be generated. But now this is not an option, if I do not go to the "legacy", which is useless. The background color does not seem to support transparency. Even if in ic_launcher.xmlI set the background to a transparent color, but the icon is still displayed with a black background.

Here is my ic_lancher.xml

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/transparent"/>
    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

And ic_launcher_round.xml is the same. The bit @color/transparentis as follows:

<color name="transparent">#00000000</color>
+14
source share
3

TL; DR

.

Android 8.0, <background> ; , .

AdaptiveIconDrawable, . https://developer.android.com/reference/android/graphics/drawable/AdaptiveIconDrawable.html
<adaptive-icon> :

XML- <adaptive-icon> .

draw AdaptiveIconDrawable.java:

@Override
public void draw(Canvas canvas) {
    if (mLayersBitmap == null) {
        return;
    }
    if (mLayersShader == null) {
        mCanvas.setBitmap(mLayersBitmap);
        mCanvas.drawColor(Color.BLACK);
        for (int i = 0; i < mLayerState.N_CHILDREN; i++) {
            if (mLayerState.mChildren[i] == null) {
                continue;
            }
            final Drawable dr = mLayerState.mChildren[i].mDrawable;
            if (dr != null) {
                dr.draw(mCanvas);
            }
        }
        mLayersShader = new BitmapShader(mLayersBitmap, TileMode.CLAMP, TileMode.CLAMP);
        mPaint.setShader(mLayersShader);
    }
    if (mMaskBitmap != null) {
        Rect bounds = getBounds();
        canvas.drawBitmap(mMaskBitmap, bounds.left, bounds.top, mPaint);
    }
}

, Canvas . :

mCanvas.setBitmap(mLayersBitmap); // reset
mCanvas.drawColor(Color.BLACK);   // fill
for (int i = 0; i < mLayerState.N_CHILDREN; i++) { // two layers
    ...
    final Drawable dr = mLayerState.mChildren[i].mDrawable;
    ...
        dr.draw(mCanvas); // draw
    ...
}

Color.BLACK :

0xff000000

drawColor , SRC_OVER :

( ) , srcover porterduff.

, , , ( ).

NoAdaptive and Adaptive

+8

, "", - . , Android 8.0 . , , , , OEM. , - ? , .

0

just play with 8 digit hex code example: 80DCDCDC I use this a long time for transparency

-4
source

Source: https://habr.com/ru/post/1690464/


All Articles