Skip to content

Commit 3d485fd

Browse files
committed
1、优化代码
2、修改readme
1 parent 3608642 commit 3d485fd

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ class FormatTextView : BaseTextView {
129129
autoLinkMask = Linkify.WEB_URLS
130130
}
131131

132+
@Deprecated("请直接使用setFormatText", ReplaceWith("setFormatText(formatTextRes, *args)"), DeprecationLevel.ERROR)
133+
fun setFormatTextBean(@StringRes formatTextRes: Int, vararg args: BaseFormat?) {
134+
setFormatText(formatTextRes, *args)
135+
}
136+
@Deprecated("请直接使用setFormatText", ReplaceWith("setFormatText(formatTextValue, *args)"), DeprecationLevel.ERROR)
137+
fun setFormatTextBean(formatTextValue: String?, vararg args: BaseFormat?) {
138+
setFormatText(formatTextValue, *args)
139+
}
140+
132141
override fun setText(text: CharSequence?, type: BufferType?) {
133142
if (isClearTexts){
134143
isDrawGradient = true

README-zh.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
}
9494
})
9595
//设置数据
96-
textView.setFormatTextBean("%1\$s欢迎欢迎欢迎欢迎欢迎欢迎%3\$s欢迎欢迎欢迎%2\$s",
96+
textView.setFormatText("%1\$s欢迎欢迎欢迎欢迎欢迎欢迎%3\$s欢迎欢迎欢迎%2\$s",
9797
FormatText().apply {
9898
textSize = 30f
9999
textColor = R.color.colorAccent
@@ -140,17 +140,17 @@ OnFormatClickListener 的 onLabelClick 返回的 position 就是设置数据的
140140

141141
有这样一段文本 str = "我已阅读并同意%1$s和%2$s" 或者 "我已阅读并同意%2$s和%1$s"
142142

143-
当使用以上两个字符串调用 setFormatTextBean(str,"隐私政策","用户协议") 时
143+
当使用以上两个字符串调用 setFormatText(str,"隐私政策","用户协议") 时
144144

145145
以上两种字符串的结果分别是
146146

147147
1、我已阅读并同意**隐私政策****用户协议**
148148

149149
2、我已阅读并同意**用户协议****隐私政策**
150150

151-
出现以上两种结果是只是因为 **%1$s****%2$s** 调换了顺序,但是调用**setFormatTextBean**设置数据的顺序并没有变化,所以当点击**隐私政策**时position两种情况都是0,当点击**用户协议**时position两种情况都是1
151+
出现以上两种结果是只是因为 **%1$s****%2$s** 调换了顺序,但是调用**setFormatText**设置数据的顺序并没有变化,所以当点击**隐私政策**时position两种情况都是0,当点击**用户协议**时position两种情况都是1
152152

153-
**简单来说 setFormatTextBean(str,"隐私政策","用户协议") 中 "隐私政策" 对应 position 是0, "用户协议" 对应 position 是1**
153+
**简单来说 setFormatText(str,"隐私政策","用户协议") 中 "隐私政策" 对应 position 是0, "用户协议" 对应 position 是1**
154154

155155
### Java调用示例
156156

@@ -175,7 +175,7 @@ textView.setOnInflateImageListener(new FormatTextView.OnInflateImageListener() {
175175
});
176176
}
177177
});
178-
textView.setFormatTextBean("%1$s欢迎欢迎欢迎欢迎欢迎欢迎欢迎%3$s欢迎欢迎欢迎%2$s",
178+
textView.setFormatText("%1$s欢迎欢迎欢迎欢迎欢迎欢迎欢迎%3$s欢迎欢迎欢迎%2$s",
179179
new FormatText().setTextColor(R.color.colorAccent).setBold(false)
180180
.setUnderlineColor(R.color.color_red).setUnderlineMarginTop(10f).setUnderlineWidth(2f)
181181
.setUnderline(true).setItalic(true).setResValue(R.string.we)

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Support switching languages | More support for gradient fonts
9595
}
9696
})
9797
//set data
98-
textView.setFormatTextBean("%1\$s欢迎欢迎欢迎欢迎欢迎欢迎%3\$s欢迎欢迎欢迎%2\$s",
98+
textView.setFormatText("%1\$s欢迎欢迎欢迎欢迎欢迎欢迎%3\$s欢迎欢迎欢迎%2\$s",
9999
FormatText().apply {
100100
textSize = 30f
101101
textColor = R.color.colorAccent
@@ -142,17 +142,17 @@ The position returned by onLabelClick of OnFormatClickListener is the subscript
142142

143143
There is such a text str = "I have read and agree with %1$s and %2$s" or "I have read and agree with %2$s and %1$s"
144144

145-
When calling setFormatTextBean(str,"Privacy Policy","User Agreement") with the above two strings
145+
When calling setFormatText(str,"Privacy Policy","User Agreement") with the above two strings
146146

147147
The results of the above two strings are
148148

149149
1. I have read and agree to **Privacy Policy** and **User Agreement**
150150

151151
2. I have read and agree to **User Agreement** and **Privacy Policy**
152152

153-
The above two results appear only because the order of **%1$s** and **%2$s** has been exchanged, but the order of calling **setFormatTextBean** to set the data has not changed, so when clicking **Privacy Both positions are 0 when the policy** is clicked, and both positions are 1 when **User Agreement** is clicked
153+
The above two results appear only because the order of **%1$s** and **%2$s** has been exchanged, but the order of calling **setFormatText** to set the data has not changed, so when clicking **Privacy Both positions are 0 when the policy** is clicked, and both positions are 1 when **User Agreement** is clicked
154154

155-
**Simply speaking, in setFormatTextBean(str,"Privacy Policy","User Agreement"), the corresponding position of "Privacy Policy" is 0, and the corresponding position of "User Agreement" is 1**
155+
**Simply speaking, in setFormatText(str,"Privacy Policy","User Agreement"), the corresponding position of "Privacy Policy" is 0, and the corresponding position of "User Agreement" is 1**
156156

157157
### Java calling example
158158

@@ -177,7 +177,7 @@ textView.setOnInflateImageListener(new FormatTextView.OnInflateImageListener() {
177177
});
178178
}
179179
});
180-
textView.setFormatTextBean("%1$s欢迎欢迎欢迎欢迎欢迎欢迎欢迎%3$s欢迎欢迎欢迎%2$s",
180+
textView.setFormatText("%1$s欢迎欢迎欢迎欢迎欢迎欢迎欢迎%3$s欢迎欢迎欢迎%2$s",
181181
new FormatText().setTextColor(R.color.colorAccent).setBold(false)
182182
.setUnderlineColor(R.color.color_red).setUnderlineMarginTop(10f).setUnderlineWidth(2f)
183183
.setUnderline(true).setItalic(true).setResValue(R.string.we)

0 commit comments

Comments
 (0)