Skip to content

Commit

Permalink
1,修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyJingFish committed May 10, 2023
1 parent c68ace3 commit 5e668e4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class FormatText : BaseFormat() {
@JvmField
var deleteLineWidth = 0f

@JvmField
var ignorePaintShader = true


fun setTextColor(@ColorRes color: Int): FormatText {
this.textColor = color
Expand Down Expand Up @@ -120,4 +123,9 @@ class FormatText : BaseFormat() {
return this
}

fun setIgnorePaintShader(ignorePaintShader: Boolean): FormatText {
this.ignorePaintShader = ignorePaintShader
return this
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ class FormatTextView : BaseTextView {
val clickableSpan: ClickableSpan = object : FormatClickableSpan(urlSpan) {
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
if(formatText.ignorePaintShader){
ds.shader = null
}
//设置颜色
ds.color = textColor
//设置是否要下划线
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.flyjingfish.formattextviewdemo

import android.graphics.LinearGradient
import android.graphics.Shader
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.View
import android.view.View.OnClickListener
import android.view.ViewTreeObserver.OnGlobalLayoutListener
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
Expand Down Expand Up @@ -102,6 +103,7 @@ class DemoActivity : AppCompatActivity() {
underlineColor = R.color.colorPrimary
underlineMarginTop = 10f
underlineWidth = 3f
ignorePaintShader = false
},
FormatText().apply {
textSize = 30f
Expand All @@ -128,6 +130,26 @@ class DemoActivity : AppCompatActivity() {
Toast.LENGTH_SHORT
).show()
}
//
// text2.viewTreeObserver
// .addOnGlobalLayoutListener(object : OnGlobalLayoutListener {
// override fun onGlobalLayout() {
// text2.viewTreeObserver.removeOnGlobalLayoutListener(this)
// var width: Int = text2.width
// var height: Int = text2.height
// if (text2.layout != null) {
// width = text2.layout.width
// height = text2.layout.height
// }
// val mLinearGradient = LinearGradient(
// 0f, 0f, width.toFloat(), height.toFloat(), intArrayOf(
// resources.getColor(R.color.colorPrimary),
// resources.getColor(R.color.color_red)
// ), null, Shader.TileMode.MIRROR
// )
// text2.paint.shader = mLinearGradient
// }
// })
}

}

0 comments on commit 5e668e4

Please sign in to comment.