11package com.flyjingfish.formattextviewdemo
22
33import android.graphics.drawable.Drawable
4- import androidx.appcompat.app.AppCompatActivity
54import android.os.Bundle
6- import android.text.style.ImageSpan
7- import android.util.Log
85import android.widget.Toast
6+ import androidx.appcompat.app.AppCompatActivity
97import com.bumptech.glide.Glide
108import com.bumptech.glide.RequestBuilder
119import com.bumptech.glide.request.RequestOptions
1210import com.bumptech.glide.request.target.CustomTarget
1311import com.bumptech.glide.request.transition.Transition
14- import com.flyjingfish.formattextview.FormatText
1512import com.flyjingfish.formattextview.*
1613import kotlinx.android.synthetic.main.activity_main.*
1714
1815class DemoActivity : AppCompatActivity () {
1916 override fun onCreate (savedInstanceState : Bundle ? ) {
2017 super .onCreate(savedInstanceState)
2118 setContentView(R .layout.activity_demo)
22- text1.setFormatTextBean(" 我已阅读并同意%1 \$ s和%2 \$ s " ,
19+ text1.setFormatTextBean(R .string.xieyi ,
2320 FormatText ().apply {
2421 textSize = 22f
2522 textColor = R .color.colorAccent
2623 bold = false
2724 italic = true
2825 underline = true
2926 underlineColor = R .color.color_red
30- underlineMarginTop = 10f
27+ underlineMarginTop = 6f
3128 underlineWidth = 2f
32- strValue = " 《用户协议》 "
29+ resValue = R .string. User_Agreement
3330 },
3431 FormatText ().apply {
3532 textSize = 22f
@@ -38,9 +35,9 @@ class DemoActivity : AppCompatActivity() {
3835 italic = true
3936 underline = true
4037 underlineColor = R .color.colorAccent
41- underlineMarginTop = 10f
38+ underlineMarginTop = 6f
4239 underlineWidth = 2f
43- strValue = " 《隐私政策》 "
40+ resValue = R .string. Privacy_Policy
4441 }
4542 )
4643 text1.setOnFormatClickListener(object : OnFormatClickListener {
@@ -77,52 +74,52 @@ class DemoActivity : AppCompatActivity() {
7774 })
7875 }
7976 })
80- text2.setFormatTextBean(" %1 \$ s看到自己喜欢的卡通相册%4 \$ s原价%3 \$ s现价%2 \$ s " ,
77+ text2.setFormatTextBean(R .string.xiao_ming_book ,
8178 FormatText ().apply {
8279 textSize = 30f
8380 textColor = R .color.colorAccent
8481 bold = false
8582 italic = true
8683 resValue = R .string.ming
87- },
88- FormatText ().apply {
89- textSize = 30f
90- textColor = R .color.black
91- bold = false
92- italic = true
93- strValue = " ¥120元"
94- deleteLine = true
95- deleteLineColor = R .color.color_red
96- deleteLineWidth = 2f
84+ },FormatImage ().apply {
85+ imagePlaceHolder = R .mipmap.ic_launcher_round
86+ imageUrlValue = " https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fp0.itc.cn%2Fq_70%2Fimages03%2F20210227%2F6687c969b58d486fa2f23d8488b96ae4.jpeg&refer=http%3A%2F%2Fp0.itc.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1661701773&t=19043990158a1d11c2a334146020e2ce"
87+ verticalAlignment = FormatImage .ALIGN_CENTER
88+ width = 40f
89+ height = 40f
90+ marginStart = 10f
91+ marginEnd = 10f
9792 },
9893 FormatText ().apply {
9994 textSize = 30f
10095 textColor = R .color.gray
10196 bold = true
10297 italic = true
103- strValue = " ¥200元 "
98+ resValue = R .string.money_200
10499 underline = true
105100 underlineColor = R .color.colorPrimary
106101 underlineMarginTop = 10f
107102 underlineWidth = 3f
108103 },
109- FormatImage ().apply {
110- imagePlaceHolder = R .mipmap.ic_launcher_round
111- imageUrlValue = " https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fp0.itc.cn%2Fq_70%2Fimages03%2F20210227%2F6687c969b58d486fa2f23d8488b96ae4.jpeg&refer=http%3A%2F%2Fp0.itc.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1661701773&t=19043990158a1d11c2a334146020e2ce"
112- verticalAlignment = FormatImage .ALIGN_CENTER
113- width = 40f
114- height = 40f
115- marginStart = 10f
116- marginEnd = 10f
104+ FormatText ().apply {
105+ textSize = 30f
106+ textColor = R .color.black
107+ bold = false
108+ italic = true
109+ resValue = R .string.money_120
110+ deleteLine = true
111+ deleteLineColor = R .color.color_red
112+ deleteLineWidth = 2f
117113 })
118114 text2.setOnFormatClickListener(object : OnFormatClickListener {
119115 override fun onLabelClick (position : Int ) {
120- Toast .makeText(this @DemoActivity," onItemClick-item " + position,Toast .LENGTH_SHORT ).show()
116+ Toast .makeText(this @DemoActivity," onLabelClick-position= " + position,Toast .LENGTH_SHORT ).show()
121117 }
122118 })
123119 text2.setOnClickListener {
124120 Toast .makeText(this @DemoActivity," onClick-view" ,Toast .LENGTH_SHORT ).show()
125121 }
126122
127123 }
124+
128125}
0 commit comments