登录

去注册 忘记密码?

登录

注册

去登录

  • 扫码关注公众号
  • 发送“我爱安卓”
  • 即可获取验证码

注册

解锁回答区域

  • 扫码关注公众号
  • 发送“我爱安卓”

若你登陆,将永久解锁;
若未登录,仅本机解锁。

解锁回答区域

获取注册验证码

  • 扫码关注公众号
  • 发送“我爱安卓”
  • 即可获取验证码

首个支持替换/正则匹配Spannable的库

liangjingkanji   2022-02-20 20:59   收藏

创建SpannableString和创建字符串一样简单

欢迎贡献代码/问题

特点

  • 首个支持替换/正则匹配Span的库
  • 支持快速设置/添加/插入Span
  • 支持正则捕获分组
  • 全部使用CharSequence接口, 让字符串和Spanable通用

函数

使用的函数非常简单

函数介绍
setSpan设置Span
addSpan添加/插入Span或字符串
replaceSpan替换/正则替换Span或字符串
replaceSpanFirst/replaceSpanLast替换/正则替换第一个/最后一个匹配项的Span或字符串

安装

添加远程仓库根据创建项目的 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.3'

License

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.

项目地址:https://github.com/liangjingkanji/spannable