Convert Figma logo to code with AI

zzhoujay logoRichText

Android平台下的富文本解析器,支持Html和Markdown

3,911
558
3,911
136

Top Related Projects

2,740

Android markdown library (no WebView)

RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android.

2,109

Knife is a rich text editor component for writing documents in Android.

TextView to display simple HTML

Hi,Developer,Welcome to use SuperTextView !

Quick Overview

RichText is an Android library for rendering rich text content in TextView and EditText components. It supports various text styles, images, and HTML tags, making it easier to display formatted text in Android applications.

Pros

  • Easy integration with existing Android projects
  • Supports a wide range of HTML tags and text styling options
  • Provides customizable image loading and caching mechanisms
  • Offers good performance for rendering complex rich text content

Cons

  • Limited documentation and examples available
  • May require additional configuration for advanced use cases
  • Some reported issues with specific HTML tags or complex layouts
  • Lack of recent updates or maintenance (as of the last check)

Code Examples

  1. Basic usage to display rich text:
val richText = RichText.fromHtml("<p>Hello <b>World</b>!</p>")
textView.text = richText
  1. Loading images with custom ImageLoader:
RichText.from(htmlContent)
    .imageLoader(GlideImageLoader()) // Custom image loader
    .into(textView)
  1. Handling URL clicks:
RichText.from(htmlContent)
    .urlClick { url ->
        // Handle URL click
        Toast.makeText(context, "Clicked: $url", Toast.LENGTH_SHORT).show()
        true
    }
    .into(textView)
  1. Customizing text appearance:
RichText.from(htmlContent)
    .textColor(Color.BLUE) // Set text color
    .fontSize(16) // Set font size in sp
    .fontFamily("sans-serif-light") // Set font family
    .into(textView)

Getting Started

To use RichText in your Android project, follow these steps:

  1. Add the dependency to your app's build.gradle file:
dependencies {
    implementation 'com.zzhoujay.richtext:richtext:3.0.8'
}
  1. In your Activity or Fragment, use RichText to display rich text content:
import com.zzhoujay.richtext.RichText

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val textView = findViewById<TextView>(R.id.textView)
        val htmlContent = "<p>This is <b>bold</b> and <i>italic</i> text.</p>"

        RichText.from(htmlContent).into(textView)
    }
}

This will render the HTML content in the TextView with proper formatting.

Competitor Comparisons

2,740

Android markdown library (no WebView)

Pros of Markwon

  • More comprehensive Markdown support, including tables, task lists, and LaTeX
  • Extensible plugin system for customization and additional features
  • Active development with frequent updates and community support

Cons of Markwon

  • Steeper learning curve due to more complex API
  • Larger library size, which may impact app size
  • Potentially slower rendering for complex Markdown content

Code Comparison

Markwon:

val markwon = Markwon.create(context)
val markdown = "**Hello** _Markdown_!"
markwon.setMarkdown(textView, markdown)

RichText:

RichText.fromMarkdown(markdown)
    .into(textView);

Summary

Markwon offers more advanced Markdown features and customization options, making it suitable for complex rendering needs. However, it comes with a steeper learning curve and larger library size. RichText provides a simpler API and smaller footprint, which may be preferable for basic Markdown rendering tasks. The choice between the two depends on the specific requirements of your project, balancing feature richness with simplicity and performance considerations.

RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android.

Pros of richeditor-android

  • Provides a WYSIWYG editor with real-time preview
  • Supports a wide range of text formatting options and HTML tags
  • Includes JavaScript interface for easy customization and extension

Cons of richeditor-android

  • Relies on WebView, which may impact performance on some devices
  • Limited support for complex layouts and advanced text styling
  • Requires more setup and configuration compared to RichText

Code Comparison

RichText:

RichText.fromHtml(htmlString)
    .into(textView)

richeditor-android:

mEditor.setEditorHeight(200)
mEditor.setEditorFontSize(22)
mEditor.setEditorFontColor(Color.RED)
mEditor.setPlaceholder("Insert text here...")

RichText focuses on rendering rich text content in TextViews, while richeditor-android provides an editable rich text interface. RichText offers a simpler API for displaying formatted text, whereas richeditor-android provides more control over the editing experience but requires more setup. RichText is better suited for displaying rich text, while richeditor-android is ideal for creating and editing rich content within the app.

2,109

Knife is a rich text editor component for writing documents in Android.

Pros of Knife

  • Lightweight and focused on basic rich text editing features
  • Simple API for common text styling operations
  • Supports undo/redo functionality out of the box

Cons of Knife

  • Limited formatting options compared to RichText
  • Less active development and community support
  • Lacks advanced features like custom spans and image handling

Code Comparison

Knife:

knife.bold(boolean valid);
knife.italic(boolean valid);
knife.underline(boolean valid);
knife.strikethrough(boolean valid);
knife.size(int size);

RichText:

RichText.fromHtml(htmlString)
    .clickable(clickableSpan)
    .into(textView);

Summary

Knife offers a straightforward approach to basic text styling, making it suitable for simple rich text editing tasks. However, RichText provides more comprehensive formatting options and better handles complex HTML content. RichText also benefits from more active development and a larger user base, potentially leading to better long-term support and feature additions.

TextView to display simple HTML

Pros of html-textview

  • Lightweight and focused on HTML rendering
  • Supports a wider range of HTML tags and attributes
  • Better handling of complex HTML structures

Cons of html-textview

  • Less frequent updates and maintenance
  • Limited styling options compared to RichText
  • Lacks some advanced features like image loading and clickable links

Code Comparison

html-textview:

HtmlTextView htmlTextView = findViewById(R.id.html_text);
htmlTextView.setHtml("<p>Hello, <b>World!</b></p>");

RichText:

RichText.fromHtml("<p>Hello, <b>World!</b></p>")
    .into(textView);

Both libraries aim to render HTML content in Android TextViews, but they differ in implementation and feature sets. html-textview focuses on accurate HTML rendering with support for more tags, while RichText offers a more comprehensive set of features for rich text display, including image loading and link handling. The choice between the two depends on the specific requirements of your project and the complexity of the HTML content you need to display.

Hi,Developer,Welcome to use SuperTextView !

Pros of SuperTextView

  • More comprehensive text styling options, including gradients and shadows
  • Built-in support for custom shapes and borders
  • Easier integration of icons and drawables within the text view

Cons of SuperTextView

  • Larger library size due to additional features
  • Steeper learning curve for utilizing all available options
  • May be overkill for simple rich text formatting needs

Code Comparison

SuperTextView:

<com.coorchice.library.SuperTextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:stv_text="Hello, SuperTextView!"
    app:stv_solid="#4D4D4D"
    app:stv_corner="5dp"
    app:stv_strokeColor="#FF4081"
    app:stv_strokeWidth="1dp" />

RichText:

RichText.fromHtml("<font color='red'>Hello, RichText!</font>")
    .into(textView);

Summary

SuperTextView offers more advanced styling options and built-in features for complex text views, while RichText focuses on simpler rich text formatting. SuperTextView may be preferred for projects requiring extensive customization, whereas RichText is more suitable for basic HTML-like text styling needs. The choice between the two depends on the specific requirements of your project and the level of complexity you're willing to manage.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

RichText Download

注意:此项目已不再维护

Android平台下的富文本解析器

  • 流式操作
  • 低侵入性
  • 依赖少,只依赖了disklrucache和support v4
  • 支持Html和Markdown格式文本
  • 支持图片点击和长按事件
  • 链接点击事件和长按事件
  • 支持设置加载中和加载错误时的图片
  • 支持自定义超链接的点击回调
  • 支持修正图片宽高
  • 支持GIF图片
  • 支持Base64编码、本地图片和Assets目录图片
  • 自持自定义图片加载器、图片加载器
  • 支持内存和磁盘双缓存
  • 已经加入对自定义Html解析器的支持

效果

演示

gradle中引用的方法

compile 'com.zzhoujay.richtext:richtext:latest-version'

使用新的Html解析器

只需加入此依赖即可,无须其他操作,新Html解析器对原生Html解析器的功能做了补充

compile 'com.zzhoujay:html:latest-version'

新Html解析器增加了对代码块的支持,代码块可以触发点击事件,通过urlClick设置, 代码块回调的参数由code://开头

使用新Html解析器遇到问题请在https://github.com/zzhoujay/Htm提issue

关于issue

最近一段时间会比较忙,issue不能及时处理,一般会定时抽空集中解决issue,但时间有限解决速度上不敢保证。

欢迎提交pull request帮助完善这个项目

注意

在第一次调用RichText之前先调用RichText.initCacheDir()方法设置缓存目录

ImageFixCallback的回调方法不一定是在主线程回调,注意不要进行UI操作

本地图片由根路径\开头,Assets目录图片由file:///android_asset/开头

Gif图片播放不支持硬件加速,若要使用Gif图片请先关闭TextView的硬件加速

textView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

使用方式

多看wiki、多看wiki、多看wiki,重要的事情说三遍

关于自定义的Html解析器

Html解析器子项目:Html

关于Markdown

Markdown源于子项目:Markdown

若在markdown解析过程中发现什么问题可以在该项目中反馈

关于富文本编辑器

编辑器开发已暂停,RichEditor

具体使用请查看demo

ListView Demo、 RecyclerView Demo、 Gif Demo

License

The MIT License (MIT)

Copyright (c) 2016 zzhoujay

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

by zzhoujay