Android custom horizontal gradient progress bar

First look at the effect of the progress bar:

Specific implementation:

Create a new class, inherit from view, and draw in OnDraw:

Some resource files used are as follows:

Note that in the above java code, mpaint. SetColor (getresources(). Getcolor (r.color. White)); This line is very important because the progress bar has three layers in total. The first layer is the outermost background, the second layer is the progress, and the third layer is drawn only if it is not 100%. Because the background of the first layer has transparency, SetColor sets the transparency, but although setshader, the transparency will still work. The two effects are superimposed, and the effect is as follows:

After adding, paint sets SetColor (white without transparency) and setshader for the second time, and the progress bar will achieve satisfactory results only when setshader takes effect;

Usage:

In Java code:

In XML file (it can be displayed without text):

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>