vxh.viet
2/28/2017 - 3:51 AM

Alpha

Alpha

Be careful with Alpha

Source: Romain Guy, Google IO, Romain Guy

In general change the alpha of the content not the view itself:

//not this
textView.setAlpha(alpha);

//but this
int newTextColor = (int) (0xFF * alpha) << 24 | baseTextColor & 0xFFFFFF;
textView.setTextColor(newTextColor);
//not this
imageView.setAlpha(alpha);

//but this
imageView.setImageAlpha((int) (alpha * 255));
//not this
customView.setAlpha(alpha);

//but this
int alpha = (int) (255 * slider.getProgress() / 100.0f);
paint.setAlpha(alpha);
canvas.draw*(..., paint);