Giter Site home page Giter Site logo

spannablestringbuilder's Introduction

SpannableStringBuilder

参考自:https://github.com/jaychang0917/SimpleText

 

Kotlin编写,封装常用的Span,简化SpannableString的编写

 

⚠️注意:由于SpannableString同时设置了ClickableSpan和ForegroundColorSpan后,发现ForegroundColorSpan不生效, 所以先设置点击事件onClick(即先设置ClickableSpan),再设置textColor (即ForegroundColorSpan)

 

调用比较简单:

 val content1 = MySpannableString(this, "前往下一步即表示您已阅读并接受Booking.com之条款及细则和隐私条款")
            .first("条款及细则").size(25).onClick(tvContent) { showToast(this, "条款及细则") }.textColor(R.color.color_main)
            .underline()
            .first("隐私条款").size(25).onClick(tvContent) { showToast(this, "隐私条款") }.textColor(R.color.color_main)
            .underline()
            .first("下一步").strikethrough().bold().scaleSize(2)

        tvContent.text = content1


        val content2 = MySpannableString(this, "Booking.com之条款及细则和隐私条款")
            .bullet(40, R.color.black)
        textView.text = content2

其中first(“XXX”)代表第一个出现的目标子串,后续的onClick() size()等都是对该目标子串的设置

效果图:

支持的Span:

 

  • AbsoluteSizeSpan
  • RelativeSizeSpan
  • StyleSpan
  • TypefaceSpan
  • StrikethroughSpan
  • UnderlineSpan
  • BulletSpan
  • ForegroundColorSpan
  • SubscriptSpan
  • SuperscriptSpan
  • ClickableSpan

spannablestringbuilder's People

Contributors

chenyucheng97 avatar

Stargazers

Wye avatar  avatar Jarvis Semou avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

wuqifeng

spannablestringbuilder's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.