Skip to content

Commit 5d33d9f

Browse files
committed
fix bug, add color
1 parent 997e905 commit 5d33d9f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

library/src/main/java/xyz/junerver/ssktx/TextView.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import android.text.method.LinkMovementMethod
1414
import android.text.style.*
1515
import android.view.View
1616
import android.widget.TextView
17+
import androidx.annotation.ColorInt
1718
import androidx.annotation.ColorRes
1819
import androidx.annotation.DrawableRes
1920
import androidx.annotation.Size
@@ -96,6 +97,7 @@ interface DslSpanBuilder {
9697
//设置文字颜色
9798
fun setForegroundColor(@Size(min = 1) colorString: String)
9899
fun setForegroundColor(@ColorRes colorId: Int)
100+
fun setForegroundColor(@ColorInt color: Int, isRes: Boolean = false)
99101
//设置文字布局
100102
fun setAlignment(align: Layout.Alignment)
101103
//设置文字大小
@@ -172,6 +174,11 @@ class DslSpanBuilderImpl(private val textView: TextView) : DslSpanBuilder {
172174
spanList.add(foregroundColorSpan)
173175
}
174176

177+
override fun setForegroundColor(@ColorInt color: Int, isRes: Boolean) {
178+
foregroundColorSpan = ForegroundColorSpan(color)
179+
spanList.add(foregroundColorSpan)
180+
}
181+
175182
override fun setAlignment(align: Layout.Alignment) {
176183
alignmentSpan = AlignmentSpan.Standard(align)
177184
spanList.add(alignmentSpan)
@@ -245,7 +252,7 @@ class DslSpanBuilderImpl(private val textView: TextView) : DslSpanBuilder {
245252
}
246253

247254
override fun setStyle(style: Int) {
248-
if (style in Typeface.NORMAL..Typeface.BOLD_ITALIC) {
255+
if (style in IntRange(Typeface.NORMAL,Typeface.BOLD_ITALIC)) {
249256
styleSpan = StyleSpan(style)
250257
spanList.add(styleSpan)
251258
}

0 commit comments

Comments
 (0)