Android uses HTML rendering to implement the example of * in front of mandatory items

The effect picture of the project's basic personal information UI interface is as follows, with a red * sign, which is different from the text color next to it. Jane friends, how did you achieve it? Here I mainly introduce a method of HTML rendering

At the beginning, I tested using a textview to load the compliance separately. I found that if the color needs to be changed, all textviews need to change the color. Then I tested using a textview to load the compliance and the corresponding text together, but I found that the height of the * symbol is not easy to control. Finally, I think it is the best way to render with HTML. No more, let's start the text.

1. XML layout (select only the corresponding part)

The * symbol and text here actually share a textview

2. Create corresponding string resource

Here, you can set the color and bold of * symbol and text separately

3. Rendering in Java code

Here you can achieve the effect in the rendering. If you change the color and size of the * symbol and text, you can change it uniformly in the string resource.

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