SpanDsl

class SpanDsl

DSL Spannable

sample: ```kotlin TextView.text = spannable { "this is real text.".text() "spannable".color(Color.BLUE).style(Typeface.BOLD) }

Types

Link copied to clipboard
object Companion

Functions

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

AbsoluteSizeSpan 设置文本绝对大小

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

AlignmentSpan 设置段落对齐方式

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

BackgroundColorSpan 背景颜色

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

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

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

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

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

SimpleClickableSpan 设置文本点击效果

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

ForegroundColorSpan 文本颜色

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

自定义字符样式

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

自定义段落样式

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

GlideImageSpan 图片

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

CenterImageSpan 图片

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

ParagraphBitmapSpan 设置段落图片

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

ParagraphDrawableSpan 设置段落图片

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

LeadingMarginSpan 设置段落文本缩进

Link copied to clipboard
fun Any?.lineBackground(@ColorInt color: Int)
fun Any?.lineBackground(colorString: String)

LineBackgroundSpan 设置段落背景颜色

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

LineHeightSpan 设置段落行高

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

MarginSpan 设置文本间距

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

MaskFilterSpan 设置文本蒙版效果

Link copied to clipboard
fun CharSequence?.mixed(replaceRule: Any? = null, span: SpanDsl.() -> Unit = {})

为 @receiver 设置多个Span

Link copied to clipboard
fun <T> T?.newline(@IntRange(from = 1) lines: Int = 1): CharSequence?

换行(可自行处理\n)

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

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

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

RelativeSizeSpan 设置文本相对大小

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

ScaleXSpan X轴文本缩放

Link copied to clipboard
fun CharSequence?.span(replaceRule: Any? = null, span: SpanDsl.() -> Unit = {})

为 @receiver 设置多个Span

Link copied to clipboard
fun Any?.strikethrough(replaceRule: Any? = null)

StrikethroughSpan 设置文本删除线

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

StyleSpan 设置文本样式

Link copied to clipboard
fun Any?.subscript(replaceRule: Any? = null)

SubscriptSpan 设置文本为下标

Link copied to clipboard
fun Any?.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)

SuggestionSpan 设置文本输入提示

Link copied to clipboard
fun Any?.superscript(replaceRule: Any? = null)

SuperscriptSpan 设置文本为上标

Link copied to clipboard
fun CharSequence?.text()

添加文本(无Spannable效果)

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

TextAppearanceSpan 设置字体效果spanTypeface

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

TypefaceSpan 设置字体样式

Link copied to clipboard
fun Any?.underline(replaceRule: Any? = null)

UnderlineSpan 设置文本下划线

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

URLSpan 设置文本超链接

Properties

Link copied to clipboard
var textSpannable: Spanned?

text SpannedString