Android message number reminder control usage details

preface

In QQ, there is a control to remind the number of messages. Although it is not used now, it may be used in the future, so it is not difficult to implement it.

realization

The renderings are as follows:

Post the source code first:

I inherited it directly to TextView, because TextView has setText method, so it only needs to draw a circular red background and then call setText. This is the idea of implementation.

First, override the onmeasure method to get the width and height. Because the background is a circle, we take the maximum value between the width and height, and then set the control size to a square. In the rectangle of the square, call the drawcircle method to draw a circle, and set the color of the brush to red.

Summary

When using this class in the layout file, you should set Android: gravity to center, so that the number can be centered. The reason why you do not inherit view to write is because view has to draw the number itself, which increases the difficulty and is not worth it.

Click here to download the source code.

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