Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

junerver/SpannableStringDslExtension

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpannableStringDslExtension

思路见文章在 Kotlin 中巧妙的使用 DSL 封装 SpannableStringBuilder

相比文章做了更多的扩展,利用 kotlin 语法糖做了一些有趣的事情,欢迎star & PR。

使用: implementation 'xyz.junerver.ssktx:ss-ktx:0.0.4'

通过一个扩展函数,使用 DSL 风格的代码,轻松的构建 SpannableString :

textView.buildSpannableString {
   "你可以这样,".asSpannableString {
       setBackgroundColor("#ff0099")
   }
   "还可以这样用"{
       setBackgroundColor("#ffff99")
   }
   addText("\n我已详细阅读并同意") {
       setBackgroundColor("#FF9900")
       setStyle(Typeface.BOLD_ITALIC)
       userUnderLine()
       useStrikethrough()
       setDrawableRight(R.drawable.icon_dingding, DynamicDrawableSpan.ALIGN_CENTER)
   }
   addText("\n打电话") {
       asURL("tel:10086")
   }
   addText("《隐私政策》") {
       setForegroundColor("#0099FF")
       setDrawableLeft(R.drawable.icon_wechat)
       onClick {

       }
   }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.