简体   繁体   English

如何在 Android Studio 中制作具有透明背景的图像资产? (带有选项添加图像资产)

[英]How to make image asset with transparent background in Android studio? (with option add image asset)

I have image with transparent background.我有透明背景的图像。

When i add image to resource folder, my background changes to white.当我将图像添加到资源文件夹时,我的背景变为白色。 (with android studio add image asset option) (使用 android studio 添加图像资产选项)

在此处输入图片说明

If i put image directly to resource file, image background stays transparent.如果我将图像直接放入资源文件,图像背景将保持透明。

Try this: 尝试这个:

ImageView myImage = (ImageView) findViewById(R.id.myImage);
myImage.setAlpha(127); //value: [0-255]. Where 0 is fully transparent and 255 is fully opaque

选择“操作栏和选项卡图标”而不是“启动器图标” ,您将获得所有图像所需的透明背景。

You can do it easily by doing the below, BTW the gray circle is original in the image itself. 您可以通过以下操作轻松实现,顺便说一下,灰色圆圈是图像本身中的原始颜色。

在此处输入图片说明

It will create you these 它将为您创造这些

在此处输入图片说明

Select the 选择

Icon type --- > Lagacy only 图标类型 ---> 仅Lagacy

and

shape -- > none 形状 ->

as follow 如下

在此处输入图片说明

Here is what is to be done in order to set the app icons generated to have transparent background这是为了将生成的应用程序图标设置为具有透明背景而要做的事情

Edit the ic_launcher_background.xml file generated and set it like below:编辑生成的 ic_launcher_background.xml 文件并将其设置如下:

This will remove the default background generated to be transparent color only.这将删除生成为仅透明颜色的默认背景。

Remove all the path definitions and only have the following one删除所有路径定义,只有以下一个

<path android:fillColor="#00000000"
    android:pathData="M0,0h108v108h-108z"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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