Android custom control making button showing progress

Recently, I saw that some applications do not pop up an additional progress bar when downloading files, but use the button to start the download task to directly display the download progress of files. By changing its background color, push from left to right until the whole button is filled, which means that the download task is completed.

In addition to this effect, I also see that a cool video client will add a stroke effect to the button corresponding to the watched video. Four edges, each representing 25% progress, starting from the top edge, clockwise and finally to the left edge, representing 100% progress. This effect is also very good.

I also studied it and wrote a custom button. The following is the effect,

Normal fill effect:

Stroke effect:

The main implementation of a custom button is to inherit the button and override the ondraw() method. The filling effect is relatively simple:

The stroke effect is relatively complex to realize, which is actually cumbersome:

Remember to execute super onDraw(canvas);

This will make the fill or stroke draw at the bottom, and will not block the original content of the button.

Then add an API to update the progress:

The demo code is uploaded to GitHub: https://github.com/YoungLeeForeverBoy/ProgressButton

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
分享
二维码
< <上一篇
下一篇>>