Java how to make background image transparent in android studio

Java how to make background image transparent in android studio

To make the background image of a view transparent in Android Studio, you can use the setAlpha method of the ImageView class.

Here is an example of how you can make the background image of an ImageView transparent in Android Studio:

refer to:‮ttual‬uri.com
ImageView imageView = findViewById(R.id.image_view);

// set the alpha value (transparency) of the image
imageView.setAlpha(0.5f); // 50% transparent

In this example, the setAlpha method is used to set the alpha value (transparency) of the imageView to 0.5f, which is equivalent to 50% transparent.

You can also use the setImageAlpha method of the ImageView class to set the alpha value of the image:

ImageView imageView = findViewById(R.id.image_view);

// set the alpha value (transparency) of the image
imageView.setImageAlpha(128); // 50% transparent

In this example, the setImageAlpha method is used to set the alpha value of the imageView to 128, which is equivalent to 50% transparent.

Keep in mind that the alpha value of an image can range from 0 (fully transparent) to 255 (fully opaque).

Created Time:2017-11-03 23:27:10  Author:lautturi