Rich text parser

Keywords: Android encoding Gradle OkHttp



Rich text parser on Android platform

  • Streaming operation
  • Low invasiveness
  • Support Html and Markdown format text
  • Support image click and long press events
  • Link click event and long press event
  • Support setting pictures in loading and loading errors
  • Support the click callback of custom hyperlink
  • Support correction of image width and height
  • GIF image support
  • Base64 encoding support
  • Self contained custom image loader

  • Support memory and disk double cache

Methods of reference in gradle

compile 'com.zzhoujay.richtext:richtext:2.5.2'

Basic use


Set data source type

Direct setting

// Set to Html

// Set to Markdown

Set using the type method



       .from(text) // data source
       .type(RichText.TYPE_MARKDOWN) // Data format. If it is not set, the default is Html. If fromMarkdown is used, the default is Markdown
       .autoFix(true) // Auto repair or not, true by default
       .autoPlay(true) // Whether gif picture plays automatically
       .showBorder(true) // Show picture borders or not
       .borderColor(Color.RED) // Picture border color
       .borderSize(10) // Border size
       .borderRadius(50) // Picture border fillet radian
       .scaleType(ImageHolder.ScaleType.FIT_CENTER) // Picture zooming
       .size(ImageHolder.MATCH_PARENT, ImageHolder.WRAP_CONTENT) // Width and height of image space
       .fix(imageFixCallback) // Set custom repair picture width and height
       .fixLink(linkFixCallback) // Set link custom callback
       .noImage(true) // Don't show and don't load pictures
       .resetSize(false) // By default, false, whether to ignore the width and height dimension in the img tag (only valid if there is a width and height in the img tag). true: ignore the size in the tag and trigger the size  ready callback. False: use the width and height dimension in the img tag, and do not trigger the size  ready callback
       .clickable(true) // Clickable. By default, you can click only when click monitoring is set
       .imageClick(onImageClickListener) // Set picture click callback
       .imageLongClick(onImageLongClickListener) // Set picture long press callback
       .urlClick(onURLClickListener) // Set link click callback
       .urlLongClick(onUrlLongClickListener) // Set link long press callback
       .placeHolder(placeHolder) // Set the bitmap displayed in the load
       .error(errorImage) // Set error graph for load failure
       .cache(Cache.ALL) // Cache type, default is Cache.ALL (CACHE picture and picture size information and text style information)
       .imageGetter(yourImageGetter) // Set the image loader, DefaultImageGetter by default, and use okhttp to implement
       .bind(tag) // Bind richText object to an object for later cleaning
       .done(callback) // Parsing completion callback
       .into(textView); // Set target TextView

Release resources

If necessary, you can call the clear method of the RichText object to release resources, but in many cases you do not need to do so

// Load rich text

// When activity ondestroy

Call RichText.recycle() when the app exits

Posted by perrio on Tue, 24 Mar 2020 09:19:19 -0700