textview html table,GitHub - Zachary790/html-textview: TextView to display simple HTML content

HtmlTextView for Android

HtmlTextView is an extended TextView component for Android, which can load HTML and converts it into Spannable for displaying it.

It is a replacement for usage of the WebView component, which behaves strange on some Android versions, flickers while loading, etc.

The library also includes a workaround to prevent TextView from crashing on specific Android versions and the possibility to load images from local drawables folder or from the Internet.

This library is kept tiny without external dependencies.

I am using it to provide Help/About Activities in my apps.

How to import

Add this to your build.gradle:

repositories {

jcenter()

}

dependencies {

compile 'org.sufficientlysecure:html-textview:3.5'

}

Example

android:id="@+id/html_text"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:textAppearance="@android:style/TextAppearance.Small" />

HtmlTextView htmlTextView = (HtmlTextView) view.findViewById(R.id.html_text);

// loads html from string and displays cat_pic.png from the app's drawable folder

htmlTextView.setHtml("

Hello wold

  • cats
  • dogs
%5C%22cat_pic%5C%22",

new HtmlResImageGetter(htmlTextView));

or

HtmlTextView htmlTextView = (HtmlTextView) view.findViewById(R.id.html_text);

// loads html from string and displays cat_pic.png from the app's assets folder

htmlTextView.setHtml("

Hello wold

  • cats
  • dogs
%5C%22cat_pic%5C%22",

new HtmlAssetsImageGetter(htmlTextView));

or

HtmlTextView htmlTextView = (HtmlTextView) view.findViewById(R.id.html_text);

// loads html from string and displays http://www.example.com/cat_pic.png from the Internet

htmlTextView.setHtml("

Hello wold

cat_pic.png%5C%22",

new HtmlHttpImageGetter(htmlTextView));

or

HtmlTextView htmlTextView = (HtmlTextView) view.findViewById(R.id.html_text);

// loads html from raw resource, i.e., a html file in res/raw/,

// this allows translatable resource (e.g., res/raw-de/ for german)

htmlTextView.setHtml(R.raw.help, new HtmlHttpImageGetter(htmlTextView));

Supported HTML tags

Tags supported by Android (history of Html class)

handled exactly like
,
,
,
,
,

...

Extended support by HtmlTextView

  1. Support for HTML tables

    HtmlTextView now supports HTML tables (to a limited extent) by condensing the text into a link which developers are able to render in a native WebView. To take advantage of the feature you'll need to:

    implement a ClickableTableSpan which provides access to the table HTML (which can be forwarded to a WebView)

    provide a DrawTableLinkSpan which defines what the table link should look like (i.e. text, text color, text size)

    Take a look at the project's sample app for an example.

    We recognize the standard table tags:

    as well as the tags extended by HtmlTextView. However, support doesn’t currently extend to tags natively supported by Android (e.g. , ,

    ) which means tables will not include the extra styling.

    Changelog

    3.5

    Allow image compression

    3.4

    Fix textIsSelectable

    3.3

    Fix text cutting bug

    prevent EmptyStackException when processing malformed li tags

    3.2

    Indenting entries of ordered lists the same way as of unordered lists

    Fix OutOfMemory

    3.1

    Override handling of

    1. and
    2. tags done by newer versions of Android SDK (removes empty lines between items)

      3.0

      Removed deprecated methods and classes

      Fix out of bounds issue

      2.0

      Introduce better API

      License

      Apache License v2

      See LICENSE for full license text.

      Authors

      This library was put together by Dominik Schürmann

      Original HtmlHttpImageGetter developed by Antarix Tandon

      Original HtmlResImageGetter developed by drawk

      JellyBeanSpanFixTextView (with fix from comment) developed by Pierre-Yves Ricau

      Table support added by Richard Thai

      Contributions

      Feel free to fork and do pull requests. I am more than happy to merge them.

      Please do not introduce external dependencies.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值