Android measures the width of text

val str = "hello world"
val paint = TextPaint()
paintEnd.textSize = xxx
paintEnd.typeface = xxx
Copy the code

1.measureText

🍎 This mode is affected by textSize and Typeface

paint.measureText(str)
Copy the code

2. getTextBounds

val rect = Rect()
paint.getTextBounds(str, 0, str.length, rect)
val w: Int = rect.width()
Copy the code

3. getDesiredWidth

android.text.Layout.getDesiredWidth(str, paint)
Copy the code

Solve ClickableSpan and ForegroundColorSpan color conflicts

val clickableSpan: ClickableSpan = object : ClickableSpan() {
    override fun onClick(widget: View?).{}override fun updateDrawState(ds: TextPaint?). {
        //super.updateDrawState(ds)
        //ds? .color = ds? LinkColor // Resolve ClickableSpan and ForegroundColorSpan color conflictsds? .isUnderlineText =false // Remove the underline}}Copy the code