简体   繁体   中英

How to make the icon background of an Android app transparent?

A PNG image is to be used as the icon foreground, and the background should be completely transparent.

Using Android Studio > New Image Asset > Configure Image Asset dialog in the Asset Studio, virtually very combination of options for the background has been tried, including removing the file entirely from the path and deleting the background tags in ic_launcher.xml and ic_launcher_round.xml .

Removing the file from the path in this wizard and removing the tags from the XML files almost does the trick, but a faint black outline remains as the background (~alpha=20%). All other options for the Background Layer leave either a stark white or black background behind the foreground image when viewing the icon on the device's launcher.

Many apps manage to have a foreground only on their icons, so it is possible. What am I doing wrong here?

Update: Thank you for the quick comments! I tried both the solutions provided as answers, same result. Screen capture is uploaded as suggested.

Updating just the Legacy icon in the wizard is not sufficient, as that only changes the Legacy icon format. The newer "Adaptive" icons are required as well. Even if the background is set to a completely transparent square png, Android Studio changes it to white. If the background file is removed entirely, the wizard allows completion, but then Android Studio uses a slightly opaque black background, as shown. With respect to the uploaded image, there should be nothing behind the foreground, completely gray to in this case without any visible circle.

Screen capture from device running API 25

Method 1:

if you have a png, just copy it and paste it in drawable, and refer to image name from manifest.

<application
        android:allowBackup="true"
        android:icon="@mipmap/new_image"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/new_image"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        ....
        </application>

Method 2:

Goto file > new > image asset , make sure you select a png image (with transparent background) & set background shape to none.

在此处输入图片说明

First you have a background image to get transparent icon without any background image you can't get your icon transparent .

And if you look to get image transparent you simply use some photo editor.

Get a view of the imageButton

View v = findViewById(R.id.myImageBtn);

get the icon from the app for example Chrome

pkgnam="com.android.chrome";
Intent intent1 = ctx.getPackageManager().getLaunchIntentForPackage(pgknam);
Drawable myIcon = getPackageManager().getActivityIcon(intent1);

set the background icon the same as the foreground icon

v.setForeground(myIcon);
v.setBackground(myIcon);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM