Paint paint = new Paint(); paint.setStrokeWidth(5); paint.setColor(Color.RED); paint.setAlpha(128); // Set 50% opacity canvas.drawLine(startX, startY, endX, endY, paint);
Paint paint = new Paint(); paint.setAlpha(200); // Set 80% opacity canvas.drawBitmap(bitmap, x, y, paint);Here, the setAlpha method is applied to the Paint object used for drawing a bitmap image with 80% transparency. Overall, the android.graphics.Paint setAlpha method is a useful tool for creating dynamic and visually appealing user interfaces in Android applications.