Android richtext allows textview to easily support rich text (image imagespan, click effect, etc., similar to QQ wechat chat)

Androidrichtext helps to achieve the same effect as QQ and wechat. A textview has both text, expression and pictures. It adopts a plug-in framework, with simple code and strong expansibility.

The basic framework package has only four java files,

Richtextwrapper: the wrapper class of textview, which supports rich text and is constructed through new richtextwrapper (textview V).

Rtmovementmethod: inherits from the native linkmovementmethod of Android, rewrites the ontouchevent method, and optimizes the click response of clickspan (the text area of click response).

Resolver: an interface. When we need to implement a rich text type, we only need to write a corresponding resolver, rewrite its resolve method, and implement the rich text style to be implemented in the resolve method.

Richtexts: a collection of common methods, classes, and interfaces. Next, let's briefly introduce how to use this framework:

Addresolver can pass in any resolver to enable textview to support the rich text type we need. If you need to cancel the support of a rich text type, just do not pass in the resolver. For example, if you only need to support expression, richtextwrapper.addresolver (emotionresolver. Class); There is no need to make too many code changes, which is more flexible.

In addition, you can see that another key place is resolver; How is resolver implemented? Here, a demo is used for a simple example:

In the above example, richtextclickspan is what you must use if you need to realize the click effect, while stickerspan is to realize the image effect, and the resolver of the above clickable image is realized. Of course, the above is to pass in an icon randomly. In the real situation, you need to make some adjustments according to the content and the expected effect.

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