File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77使用:
88` implementation 'xyz.junerver.ssktx:ss-ktx:0.0.1' `
9+
10+ 通过一个扩展函数,使用 DSL 风格的代码,轻松的构建 SpannableString :
11+
12+ <img
13+ src="./art/11b3f615be00077561230273f0eb724.jpg"
14+ align=center />
15+
16+
17+ ``` kotlin
18+ textView.buildSpannableString {
19+ " 你可以这样," .asSpannableString {
20+ setBackgroundColor(" #ff0099" )
21+ }
22+ " 还可以这样用" {
23+ setBackgroundColor(" #ffff99" )
24+ }
25+ addText(" \n 我已详细阅读并同意" ) {
26+ setBackgroundColor(" #FF9900" )
27+ setStyle(Typeface .BOLD_ITALIC )
28+ userUnderLine()
29+ useStrikethrough()
30+ setDrawableRight(R .drawable.icon_dingding, DynamicDrawableSpan .ALIGN_CENTER )
31+ }
32+ addText(" \n 打电话" ) {
33+ asURL(" tel:10086" )
34+ }
35+ addText(" 《隐私政策》" ) {
36+ setForegroundColor(" #0099FF" )
37+ setDrawableLeft(R .drawable.icon_wechat)
38+ onClick {
39+
40+ }
41+ }
42+ }
43+ ```
Original file line number Diff line number Diff line change 88 android : label =" @string/app_name"
99 android : roundIcon =" @mipmap/ic_launcher_round"
1010 android : supportsRtl =" true"
11- android : theme =" @style/Theme.SpannableStringDslExtension" />
11+ android : theme =" @style/Theme.SpannableStringDslExtension" >
12+ <activity android : name =" .MainActivity"
13+ android : exported =" true" >
14+ <intent-filter >
15+ <action android : name =" android.intent.action.MAIN" />
16+
17+ <category android : name =" android.intent.category.LAUNCHER" />
18+ </intent-filter >
19+ </activity >
20+ </application >
1221
1322</manifest >
Original file line number Diff line number Diff line change @@ -30,20 +30,20 @@ class MainActivity : AppCompatActivity() {
3030 " 还可以这样用" {
3131 setBackgroundColor(" #ffff99" )
3232 }
33- addText(" 我已详细阅读并同意 " ) {
33+ addText(" \n 我已详细阅读并同意 " ) {
3434 setBackgroundColor(" #FF9900" )
3535 setStyle(Typeface .BOLD_ITALIC )
3636 userUnderLine()
3737 useStrikethrough()
3838 setDrawableRight(R .drawable.icon_dingding, DynamicDrawableSpan .ALIGN_CENTER )
3939 }
40- addText(" 打电话 " ) {
40+ addText(" \n 打电话 " ) {
4141 asURL(" tel:10086" )
4242 }
4343 addText(" 《隐私政策》" ) {
4444 setForegroundColor(" #0099FF" )
4545 setDrawableLeft(R .drawable.icon_wechat)
46- onClick() {
46+ onClick {
4747
4848 }
4949 }
You can’t perform that action at this time.
0 commit comments