Implementation of Android text stroke function

Here also want to briefly say that these small modules were not my original, but also found by looking up the materials at that time. Due to a long time, the original links have been forgotten, so the reference links are not listed here. However, I have modified and improved these codes and added some comments. I hope they will be helpful to you.

The function of text stroke is very practical. If the text is displayed under a single background, text stroke can also play a decorative role. If the text is displayed in a complex background, especially in different picture backgrounds, because the text color is easy to be similar to the picture background, resulting in unclear text and poor user experience. If the text is stroked with different colors, the outline of the text will be one color and the interior of the text will be another color, because generally, the picture is either similar to the outline of the text or similar to the interior of the text. In this way, the text will be displayed as a whole no matter how complex the background of the picture is.

The method I use here is to override the textview mode.

The following is the relevant code. It is relatively simple and easy to understand.

The inherited textview text stroke classes are as follows:

The layout file is as follows:

The calling code is as follows:

If you want to change the text stroke width or stroke color, you need to modify the stroketextview class above. Of course, you can design this class more flexibly, so that you can dynamically modify the stroke width or stroke color.

The above is the implementation example of text stroke function in Android. I hope this paper will help you learn Android development. Please 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
分享
二维码
< <上一篇
下一篇>>