Span

class Span

Chain Spannable

sample:

TextView.setText(Span.create()
.text("this is real text.")
.text("spannable").color(Color.BLUE).style(Typeface.BOLD)
.spannable())

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
@JvmOverloads
fun absoluteSize(size: Int, dp: Boolean = true, replaceRule: Any? = null): Span

AbsoluteSizeSpan 设置文本绝对大小

Link copied to clipboard
fun alignment(align: Layout.Alignment): Span

AlignmentSpan 设置段落对齐方式

Link copied to clipboard
@JvmOverloads
fun background(@ColorInt color: Int, replaceRule: Any? = null): Span
@JvmOverloads
fun background(colorString: String, replaceRule: Any? = null): Span

BackgroundColorSpan 背景颜色

Link copied to clipboard
@JvmOverloads
fun blurMask(@FloatRange(from = 0.0) radius: Float, style: BlurMaskFilter.Blur? = null, replaceRule: Any? = null): Span

BlurMaskFilter 设置文本模糊滤镜蒙版效果

Link copied to clipboard
@JvmOverloads
fun bullet(@ColorInt color: Int, @Px @IntRange(from = 0) bulletRadius: Int, @Px gapWidth: Int = 0): Span
@JvmOverloads
fun bullet(colorString: String, @Px @IntRange(from = 0) bulletRadius: Int, @Px gapWidth: Int = 0): Span

BulletSpan 设置段落项目符号(段落前圆形标识)

Link copied to clipboard
@JvmOverloads
fun clickable(@ColorInt color: Int? = null, @ColorInt backgroundColor: Int? = null, style: Int? = null, config: SimpleClickableConfig? = null, replaceRule: Any? = null, onClick: OnSpanClickListener? = null): Span

SimpleClickableSpan 设置文本点击效果

Link copied to clipboard
@JvmOverloads
fun color(@ColorInt color: Int, replaceRule: Any? = null): Span
@JvmOverloads
fun color(colorString: String, replaceRule: Any? = null): Span

ForegroundColorSpan 文本颜色

Link copied to clipboard
@JvmOverloads
fun <T : CharacterStyle> custom(style: T, replaceRule: Any? = null): Span

自定义字符样式

@JvmOverloads
fun <T : ParagraphStyle> custom(style: T, replaceRule: Any? = null): Span

自定义段落样式

Link copied to clipboard
@JvmOverloads
fun glide(view: TextView, url: Any, useTextViewSize: TextView? = null, size: DrawableSize? = null, @Px marginLeft: Int? = null, @Px marginRight: Int? = null, align: GlideImageSpan.Align? = null, loopCount: Int? = null, requestOption: RequestOptions? = null, replaceRule: Any? = null): Span

GlideImageSpan 图片

Link copied to clipboard
@JvmOverloads
fun image(context: Context, bitmap: Bitmap, useTextViewSize: TextView? = null, size: DrawableSize? = null, @Px marginLeft: Int? = null, @Px marginRight: Int? = null, align: CenterImageSpan.Align? = null, replaceRule: Any? = null): Span
@JvmOverloads
fun image(context: Context, uri: Uri, useTextViewSize: TextView? = null, size: DrawableSize? = null, @Px marginLeft: Int? = null, @Px marginRight: Int? = null, align: CenterImageSpan.Align? = null, replaceRule: Any? = null): Span
@JvmOverloads
fun image(context: Context, @DrawableRes resourceId: Int, useTextViewSize: TextView? = null, size: DrawableSize? = null, @Px marginLeft: Int? = null, @Px marginRight: Int? = null, align: CenterImageSpan.Align? = null, replaceRule: Any? = null): Span
@JvmOverloads
fun image(drawable: Drawable, source: String? = null, useTextViewSize: TextView? = null, size: DrawableSize? = null, @Px marginLeft: Int? = null, @Px marginRight: Int? = null, align: CenterImageSpan.Align? = null, replaceRule: Any? = null): Span

CenterImageSpan 图片

Link copied to clipboard
@JvmOverloads
fun imageParagraph(bitmap: Bitmap, @Px padding: Int = 0, useTextViewSize: TextView? = null, size: DrawableSize? = null): Span

ParagraphBitmapSpan 设置段落图片

@JvmOverloads
fun imageParagraph(drawable: Drawable, @Px padding: Int = 0, useTextViewSize: TextView? = null, size: DrawableSize? = null): Span

ParagraphDrawableSpan 设置段落图片

Link copied to clipboard
@JvmOverloads
fun leadingMargin(@IntRange(from = 1) firstLines: Int, @Px firstMargin: Int, @Px restMargin: Int = 0): Span

LeadingMarginSpan 设置段落文本缩进

Link copied to clipboard
fun lineBackground(@ColorInt color: Int): Span
fun lineBackground(colorString: String): Span

LineBackgroundSpan 设置段落背景颜色

Link copied to clipboard
fun lineHeight(@Px @IntRange(from = 1) height: Int): Span

LineHeightSpan 设置段落行高

Link copied to clipboard
@JvmOverloads
fun margin(@Px width: Int, @ColorInt color: Int = Color.TRANSPARENT, replaceRule: Any? = null): Span
@JvmOverloads
fun margin(@Px width: Int, colorString: String?, replaceRule: Any? = null): Span

MarginSpan 设置文本间距

Link copied to clipboard
@JvmOverloads
fun maskFilter(filter: MaskFilter, replaceRule: Any? = null): Span

MaskFilterSpan 设置文本蒙版效果

Link copied to clipboard
@JvmOverloads
fun newline(@IntRange(from = 1) lines: Int = 1): Span

换行(可自行处理\n)

Link copied to clipboard
@JvmOverloads
fun quote(@ColorInt color: Int, @Px @IntRange(from = 0) stripeWidth: Int = 10, @Px @IntRange(from = 0) gapWidth: Int = 0): Span
@JvmOverloads
fun quote(colorString: String, @IntRange(from = 0) stripeWidth: Int = 10, @IntRange(from = 0) gapWidth: Int = 0): Span

QuoteSpan 设置段落引用样式(段落前竖线标识)

Link copied to clipboard
@JvmOverloads
fun relativeSize(@FloatRange(from = 0.0) proportion: Float, replaceRule: Any? = null): Span

RelativeSizeSpan 设置文本相对大小

Link copied to clipboard
fun saveCache(): Span

保存当前 text spannable(大部分情况不需要手动调用)

Link copied to clipboard
@JvmOverloads
fun scaleX(@FloatRange(from = 0.0) proportion: Float, replaceRule: Any? = null): Span

ScaleXSpan X轴文本缩放

Link copied to clipboard
fun spannable(): CharSequence

构建Spannable

Link copied to clipboard
@JvmOverloads
fun strikethrough(replaceRule: Any? = null): Span

StrikethroughSpan 设置文本删除线

Link copied to clipboard
@JvmOverloads
fun style(style: Int, replaceRule: Any? = null): Span

StyleSpan 设置文本样式

Link copied to clipboard
@JvmOverloads
fun subscript(replaceRule: Any? = null): Span

SubscriptSpan 设置文本为下标

Link copied to clipboard
@JvmOverloads
fun suggestion(context: Context, suggestions: Array<String>, flags: Int = SuggestionSpan.FLAG_EASY_CORRECT or SuggestionSpan.FLAG_AUTO_CORRECTION, locale: Locale? = null, notificationTargetClass: Class<*>? = null, replaceRule: Any? = null): Span

SuggestionSpan 设置文本输入提示

Link copied to clipboard
@JvmOverloads
fun superscript(replaceRule: Any? = null): Span

SuperscriptSpan 设置文本为上标

Link copied to clipboard
fun text(text: CharSequence): Span

插入待处理字符串 在使用stylecolor... 等等之前,需调用该方法插入当前需要处理的字符串

Link copied to clipboard
@JvmOverloads
fun textAppearance(style: Int = Typeface.NORMAL, @Px size: Int = -1, @ColorInt color: Int? = null, family: String? = null, linkColor: ColorStateList? = null, replaceRule: Any? = null): Span

TextAppearanceSpan 设置字体效果spanTypeface

Link copied to clipboard
@JvmOverloads
fun typeface(typeface: Typeface? = null, family: String? = null, replaceRule: Any? = null): Span

TypefaceSpan 设置字体样式

Link copied to clipboard
@JvmOverloads
fun underline(replaceRule: Any? = null): Span

UnderlineSpan 设置文本下划线

Link copied to clipboard
@JvmOverloads
fun url(url: String, replaceRule: Any? = null): Span

URLSpan 设置文本超链接