# Html字体 **Repository Path**: chockqiu/html-font-face ## Basic Information - **Project Name**: Html字体 - **Description**: Android Html.fromHtml支持特殊字体 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: https://www.jianshu.com/p/8e0f9e719ce8 - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2022-07-19 - **Last Updated**: 2022-12-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Html字体 #### 介绍 Android Html.fromHtml支持特殊字体 #### 预览效果 ![image.png](13651212-e802683298b70bc0.webp.jpg) #### 功能说明 - 支持自定义HTML TAG,默认`... `; - 支持size属性,与原生`... `TAG一致; - 支持color属性,与原生``TAG一致; - 支持face属性,扩展原生的``,支持任意字体; #### 使用方式 在工程根目录的**build.gradle**中添加 ``` allprojects { repositories { maven { url 'https://www.jitpack.io' } ... } } ``` 添加依赖 ``` implementation 'com.gitee.chockqiu:HtmlFontFace:1.0' ``` #### 使用示例 ``` TextView tvHtml = findViewById(R.id.tvHtml); TextView tvHtml2 = findViewById(R.id.tvHtml2); TextView tvHtml3 = findViewById(R.id.tvHtml3); HtmlTagRegister reg = new HtmlTagRegister(); HtmlFontFaceHandler fontFace = new HtmlFontFaceHandler("kfont") { @Override public Typeface onNeedFontFace(String faceName) { if (faceName.equalsIgnoreCase("DIN")) { return Typeface.createFromAsset(getAssets(), "DIN_Alternate_Bold.ttf" ); } else if (faceName.equalsIgnoreCase("YouSheBiaoTiHei")) { return Typeface.createFromAsset(getAssets(), "YouSheBiaoTiHei.ttf" ); } return null; } }; reg.registerHtmlTag(fontFace); tvHtml.setText(Html.fromHtml("愿有前程可奔赴,1234567890", null, reg)); tvHtml2.setText(Html.fromHtml("亦有岁月可回首,1234567890", null, reg)); tvHtml3.setText(Html.fromHtml("且有情深共白头。1234567890", null, reg)); ```
博客地址: https://www.jianshu.com/p/8e0f9e719ce8 #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request