android color with alpha code example

Example 1: how to set opacity of background android

//And below for opacity code
Make the color have 80% in the alpha channel. For example, for red use #CCFF0000:
<TextView
   ...
   android:background="#CCFF0000" />
   
   
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60%99
55%8C
50%80
45%73
40%66
35%59
30%4D
25%40
20%33
15%26
10%1A
5%0D
0%00

Example 2: set solid color background android programatically in drawable

(view.getBackground()).setColorFilter(Color.parseColor("#FFDE03"), PorterDuff.Mode.SRC_IN);

Example 3: how to set opacity of background android

<TextView
   ...
   android:background="#CCFF0000" />

Example 4: set gradient color for android paint

paint.setShader(new LinearGradient(0, 0, 0, getHeight(), Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));
    canvas.drawPath(arrowPath, paint);

Tags:

Java Example