Android Studio Image Asset Launcher Icon Transparent Background Color

Perhaps you think this question is a duplicate of this . But since then, Android Studio has been updated, and the solution given there no longer works.

I am trying to set the logo of my application using the image resource in android studio. This is due to the fact that if I put my application logo directly in drawable or mipmap, then it causes a lot of problems, such as: if the size is large, then the application crashes, if the device runs on oreo, the logo will not be displayed and displays by default ic_launcher etc.

When I try to install the logo of my application using the image resource, I face a problem: I can not save the transparent logo of the application.

I have a png logo made in Photoshop, and I want to set it as my application logo, and I don't need any background, but the Android studio image resource does not provide any way to remove the background. I tried the following solutions from google:

this and

but none of them worked for me.

Trial Solutions:

  • By setting the form none
  • deleting ic_launcher_background default file default
  • Tested on different devices

None of these works ... please help me. Any help would be appreciated.

+4
source share
2 answers

Android 8.0 Oreo (API- 26) , : . , Android O , . , Android 8.0 , targetSdkVersion - 26 .

https://material.io/guidelines/style/icons.html#icons-icons-for-android

Android

Android O

Android O Home All Apps. , , .

...

: . .

( )

  • 108 x 108 dp
  • 72dp
  • ()

( )

  • 108 X 108 dp
  • 72dp

7.1

8.0 , 7.1 , .

  • ( ). . .
  • Launcher ( Legacy). , . shape none, .
  • res/mipmap/ic_laucher_round .
  • AndroidManifest.xml android:roundIcon="@mipmap/ic_launcher_round" application.

STEP 1

, XML Android 8.0 .

  • -anydpi-V26/ic_launcher.xml
  • -anydpi-V26/ic_launcher_round.xml

, XML .

  • /ic _launcher_background.xml
  • -v24/ic_launcher_foreground.xml

STEP 2


# 1:

Android 8.0 , Android 8.1 (Nexus 5X). "NoAdaptive" mipmap-anydpi-v26, "Adaptive" .

Home screen in Android 8.1 (Nexus 5X)Recents screen in Android 8.1 (Nexus 5X)


# 2:

Android 8.0 , . .

Nexus 5X (Android 8.1)

Google Now Launcher com.google.android.launcher. , " β„–1".

Nexus 5 (Android 8.1)

Pixel Launcher com.google.android.apps.nexuslauncher. "", :

  • " "

Home, AllApps and Recents screens in Nexus 5 emulator

GMS :

  • com.google.android.launcher Google Now Launcher
  • com.google.android.apps.nexuslauncher

, AOSP open-source. Android :

  • com.android.launcher
  • com.android.launcher2
    • Launcher2 ( )
  • com.android.launcher3

Launcher3

git oreo-release Launcher3, LauncherIcons.java wrapToAdaptiveIconDrawable, .

/**
 * If the platform is running O but the app is not providing AdaptiveIconDrawable, then
 * shrink the legacy icon and set it as foreground. Use color drawable as background to
 * create AdaptiveIconDrawable.
 */
static Drawable wrapToAdaptiveIconDrawable(Context context, Drawable drawable, float scale) {
    if (!(FeatureFlags.LEGACY_ICON_TREATMENT && Utilities.isAtLeastO())) {
        return drawable;
    }
    try {
        if (!(drawable instanceof AdaptiveIconDrawable)) {
            AdaptiveIconDrawable iconWrapper = (AdaptiveIconDrawable)
                    context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate();
            FixedScaleDrawable fsd = ((FixedScaleDrawable) iconWrapper.getForeground());
            fsd.setDrawable(drawable);
            fsd.setScale(scale);
            return (Drawable) iconWrapper;
        }
    } catch (Exception e) {
        return drawable;
    }
    return drawable;
}

FeatureFlags.LEGACY_ICON_TREATMENT FeatureFlags.java:

// When enabled, icons not supporting {@link AdaptiveIconDrawable} will be wrapped in this class.
public static final boolean LEGACY_ICON_TREATMENT = true;

, , , Pixel Launcher.

true, R.drawable.adaptive_icon_drawable_wrapper, . drawable: @color/legacy_icon_background, XML :

<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/legacy_icon_background"/>
    <foreground>
        <com.android.launcher3.graphics.FixedScaleDrawable />
    </foreground>
</adaptive-icon>

legacy_icon_background colors.xml

<color name="legacy_icon_background">#FFFFFF</color>

, .

+6

, png 512x512 px Photoshop, (mipmap-xxxhdpi to mipmap-mdpi).

Android Studio. Photoshop.

512x512px Photoshop. Android, iPhone-, , . , mipmap android zip . . 50 .

0

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


All Articles