Skip to content

Commit 5e668e4

Browse files
committed
1,修复bug
1 parent c68ace3 commit 5e668e4

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

FormatTextView/src/main/java/com/flyjingfish/formattextview/FormatText.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class FormatText : BaseFormat() {
4848
@JvmField
4949
var deleteLineWidth = 0f
5050

51+
@JvmField
52+
var ignorePaintShader = true
53+
5154

5255
fun setTextColor(@ColorRes color: Int): FormatText {
5356
this.textColor = color
@@ -120,4 +123,9 @@ class FormatText : BaseFormat() {
120123
return this
121124
}
122125

126+
fun setIgnorePaintShader(ignorePaintShader: Boolean): FormatText {
127+
this.ignorePaintShader = ignorePaintShader
128+
return this
129+
}
130+
123131
}

FormatTextView/src/main/java/com/flyjingfish/formattextview/FormatTextView.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ class FormatTextView : BaseTextView {
303303
val clickableSpan: ClickableSpan = object : FormatClickableSpan(urlSpan) {
304304
override fun updateDrawState(ds: TextPaint) {
305305
super.updateDrawState(ds)
306+
if(formatText.ignorePaintShader){
307+
ds.shader = null
308+
}
306309
//设置颜色
307310
ds.color = textColor
308311
//设置是否要下划线

app/src/main/java/com/flyjingfish/formattextviewdemo/DemoActivity.kt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.flyjingfish.formattextviewdemo
22

3+
import android.graphics.LinearGradient
4+
import android.graphics.Shader
35
import android.graphics.drawable.Drawable
46
import android.os.Bundle
5-
import android.view.View
6-
import android.view.View.OnClickListener
7+
import android.view.ViewTreeObserver.OnGlobalLayoutListener
78
import android.widget.Toast
89
import androidx.appcompat.app.AppCompatActivity
910
import com.bumptech.glide.Glide
@@ -102,6 +103,7 @@ class DemoActivity : AppCompatActivity() {
102103
underlineColor = R.color.colorPrimary
103104
underlineMarginTop = 10f
104105
underlineWidth = 3f
106+
ignorePaintShader = false
105107
},
106108
FormatText().apply {
107109
textSize = 30f
@@ -128,6 +130,26 @@ class DemoActivity : AppCompatActivity() {
128130
Toast.LENGTH_SHORT
129131
).show()
130132
}
133+
//
134+
// text2.viewTreeObserver
135+
// .addOnGlobalLayoutListener(object : OnGlobalLayoutListener {
136+
// override fun onGlobalLayout() {
137+
// text2.viewTreeObserver.removeOnGlobalLayoutListener(this)
138+
// var width: Int = text2.width
139+
// var height: Int = text2.height
140+
// if (text2.layout != null) {
141+
// width = text2.layout.width
142+
// height = text2.layout.height
143+
// }
144+
// val mLinearGradient = LinearGradient(
145+
// 0f, 0f, width.toFloat(), height.toFloat(), intArrayOf(
146+
// resources.getColor(R.color.colorPrimary),
147+
// resources.getColor(R.color.color_red)
148+
// ), null, Shader.TileMode.MIRROR
149+
// )
150+
// text2.paint.shader = mLinearGradient
151+
// }
152+
// })
131153
}
132154

133155
}

0 commit comments

Comments
 (0)