{"id":25046008,"url":"https://github.com/wangchenyan/html-text","last_synced_at":"2025-08-10T22:48:04.074Z","repository":{"id":43603757,"uuid":"92376420","full_name":"wangchenyan/html-text","owner":"wangchenyan","description":"Android RichText 富文本解析器，支持网络图片，图片和链接点击事件","archived":false,"fork":false,"pushed_at":"2020-07-22T10:08:02.000Z","size":221,"stargazers_count":195,"open_issues_count":16,"forks_count":30,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-27T17:35:23.123Z","etag":null,"topics":["android","richtext"],"latest_commit_sha":null,"homepage":"https://juejin.im/post/6844903759424798728","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wangchenyan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-25T07:17:55.000Z","updated_at":"2025-03-23T07:09:43.000Z","dependencies_parsed_at":"2022-09-10T16:32:29.952Z","dependency_job_id":null,"html_url":"https://github.com/wangchenyan/html-text","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangchenyan%2Fhtml-text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangchenyan%2Fhtml-text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangchenyan%2Fhtml-text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangchenyan%2Fhtml-text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wangchenyan","download_url":"https://codeload.github.com/wangchenyan/html-text/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248815453,"owners_count":21165929,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","richtext"],"created_at":"2025-02-06T06:34:08.907Z","updated_at":"2025-04-14T03:30:44.885Z","avatar_url":"https://github.com/wangchenyan.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# html-text\n\n[![](https://jitpack.io/v/wangchenyan/html-text.svg)](https://jitpack.io/#wangchenyan/html-text)\n\nhtml-text 是 android.text.Html 的一个扩展，可以加载 HTML 并将其转换成 Spannable 显示在 TextView 上，支持网络图片，图片加载器无绑定，支持图片和链接点击事件，扩展了更多标签。\n\n该库体积微小，仅有8个类，不需要外部依赖。\n\n## Screenshot\n\n![](https://raw.githubusercontent.com/wangchenyan/html-text/master/art/screenshot.jpg)\n\n## Supported HTML tags\n\n### Tags supported by android.text.Html\n\n- `\u003cp\u003e`\n- `\u003cdiv\u003e`\n- `\u003cbr\u003e`\n- `\u003cb\u003e`\n- `\u003ci\u003e`\n- `\u003cstrong\u003e`\n- `\u003cem\u003e`\n- `\u003cu\u003e`\n- `\u003ctt\u003e`\n- `\u003cdfn\u003e`\n- `\u003csub\u003e`\n- `\u003csup\u003e`\n- `\u003cblockquote\u003e`\n- `\u003ccite\u003e`\n- `\u003cbig\u003e`\n- `\u003csmall\u003e`\n- `\u003cfont color=\"...\" face=\"...\"\u003e`\n- `\u003ch1\u003e`, `\u003ch2\u003e`, `\u003ch3\u003e`, `\u003ch4\u003e`, `\u003ch5\u003e`, `\u003ch6\u003e`\n- `\u003ca href=\"...\"\u003e`\n- `\u003c img src=\"...\"\u003e`\n\n### Extended support by html-text\n\n- `\u003cul\u003e`\n- `\u003col\u003e`\n- `\u003cli\u003e`\n- `\u003ccode\u003e`\n- `\u003ccenter\u003e`\n- `\u003cstrike\u003e`\n- `\u003cdiv\u003e`[HTML contains two newline, there is one]\n- `\u003cfont size=\"...\" color=\"...\"\u003e`[extend support size]\n- `\u003c img src=\"...\" width=\"...\" height=\"...\"\u003e`[extend support width, height]\n\n这些是我在项目中所用到的标签，如果你需要支持更多标签，请在[Issues](https://github.com/wangchenyan/html-text/issues)中告诉我。\n\n## Usage\n\n### Gradle\n\n**Step 1.** Add the JitPack repository to your build file\n\nAdd it in your root build.gradle at the end of repositories:\n\n```\nallprojects {\n\trepositories {\n\t\t...\n\t\tmaven { url 'https://jitpack.io' }\n\t}\n}\n```\n\n**Step 2.** Add the dependency\n\n```\ndependencies {\n    implementation 'com.github.wangchenyan:html-text:1.0'\n}\n```\n\n## Sample\n\n```\nTextView textView = (TextView) findViewById(R.id.text);\ntextView.setMovementMethod(LinkMovementMethod.getInstance());\nString sample = \"\u003ch2\u003eHello wold\u003c/h2\u003e\"\n                 + \"\u003cfont size=\\\"5\\\" color=\\\"#FF0000\\\"\u003eFont size\u003c/font\u003e\"\n                 + \"\u003cimg src=\\\"http://www.sample.com\\\"/\u003e\";\nHtmlText.from(sample)\n    .setImageLoader(new HtmlImageLoader() {\n        @Override\n        public void loadImage(String url, final Callback callback) {\n            // Glide sample, you can also use other image loader\n            Glide.with(context)\n                 .load(url)\n                 .asBitmap()\n                 .into(new SimpleTarget\u003cBitmap\u003e() {\n                     @Override\n                     public void onResourceReady(Bitmap resource,\n                                                 GlideAnimation\u003c? super Bitmap\u003e glideAnimation) {\n                         callback.onLoadComplete(resource);\n                     }\n\n                     @Override\n                     public void onLoadFailed(Exception e, Drawable errorDrawable) {\n                         callback.onLoadFailed();\n                     }\n                 });\n        }\n\n        @Override\n        public Drawable getDefaultDrawable() {\n            return ContextCompat.getDrawable(context, R.drawable.image_placeholder_loading);\n        }\n\n        @Override\n        public Drawable getErrorDrawable() {\n            return ContextCompat.getDrawable(context, R.drawable.image_placeholder_fail);\n        }\n\n        @Override\n        public int getMaxWidth() {\n            return getTextWidth();\n        }\n\n        @Override\n        public boolean fitWidth() {\n            return false;\n        }\n    })\n    .setOnTagClickListener(new OnTagClickListener() {\n        @Override\n        public void onImageClick(Context context, List\u003cString\u003e imageUrlList, int position) {\n            // image click\n        }\n\n        @Override\n        public void onLinkClick(Context context, String url) {\n            // link click\n        }\n    })\n    .into(textView);\n```\n\n## Thanks\n\n- [html-textview](https://github.com/SufficientlySecure/html-textview)\n- [RichText](https://github.com/moonChenHaohui/RichText)\n\n## License\n\n    Copyright 2017 wangchenyan\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwangchenyan%2Fhtml-text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwangchenyan%2Fhtml-text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwangchenyan%2Fhtml-text/lists"}