创建SpannableString和创建字符串一样简单
欢迎贡献代码/问题
- 低学习成本
- 首个支持替换/正则匹配Span的库
- 全部使用CharSequence接口, 使用起来和字符串没有区别
- 良好扩展性, 没有自定义控件/没有多余函数
使用的函数非常简单
函数 | 介绍 |
---|---|
setSpan | 设置Span |
addSpan | 添加/插入Span或字符串 |
replaceSpan | 替换/正则替换Span或字符串 |
replaceSpanFirst/replaceSpanLast | 替换/正则替换第一个/最后一个匹配项的Span或字符串 |
本框架会收集一些常用的Span效果实现
Span | 描述 |
---|---|
CenterImageSpan | 垂直对齐方式/图片宽高/固定图片比例 |
GlideImageSpan | 加载网络图片/垂直对齐方式/图片宽高/固定图片比例, 要求依赖Glide |
ColorSpan | 快速创建文字颜色 |
HighlightSpan | 创建字体颜色/字体样式/可点击效果 |
ClickableMovementMethod | 等效LinkMovementMethod, 但没有点击背景色 |
本工具将保持简单和扩展性, 如果你想使用dsl构建span可以使用SpannableX
添加远程仓库根据创建项目的 Android Studio 版本有所不同
Android Studio Arctic Fox以下创建的项目 在项目根目录的 build.gradle 添加仓库
allprojects {
repositories {
// ...
maven { url 'https://jitpack.io' }
}
}
Android Studio Arctic Fox以上创建的项目 在项目根目录的 settings.gradle 添加仓库
dependencyResolutionManagement {
repositories {
// ...
maven { url 'https://jitpack.io' }
}
}
然后在 module 的 build.gradle 添加依赖框架
implementation 'com.github.liangjingkanji:spannable:1.0.7'
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.