首页 > 解决方案 > 如何在Android Studio中使图像中的特定颜色透明?

问题描述

我正在使用带有字母“LYIT”和白色背景的图像。我想让白色背景透明,所以只有字母可见。

我试过android:background="@android:color/transparent"了,但它只改变了图像Logo的一小部分。

app:tint="@color/colorWhite"也不行。

有没有办法可以定位图像的白色部分并使其透明?

另外,我正在用 Kotlin 编写我的课程。

谢谢

标签: androidxmlandroid-studiokotlinimageview

解决方案


我在另一个问题上找到了这个答案,您可以在后端编写以下代码

val image = findViewById<ImageView>(R.id.*write the id of the image here*)
image.background.alpha = 0 //the value of alpha's range is [0,255], 0is transperent and 255 is quite opaque

推荐阅读