Skip to content

A library to simplify your Spannable usage with many handy functions

License

Notifications You must be signed in to change notification settings

sp00ne/spanning

Repository files navigation

Spanning

A library to simplify your Spannable usage with many handy extensions

How to get it

Step 1. Add the repository in your root build.gradle at the end of repositories:

  allprojects {
      repositories {
          ...
          maven { url 'https://jitpack.io' }
      }
  }

Step 2. In the build.gradle file of your module (like app), include it like so:

  dependencies {
      implementation 'com.github.sp00ne:spanning:1.0.0'
  }

How to use it

The usage of this library is pretty straight-forward. To start building the spannable, we begin with the simple example of just returing a SpannedString:

  spannable("some text without any candy")

If you wish to add Spans to it, you simply open up a block, like so:

Single span

  spannable("some text with candy") {
      setTextColor(color)
  }

Multiple spans

Which will cause the entire text("some text with candy") to get the text color specified in the block. Spans can also be applied on top of eachother like this:

  spannable("this has many effects") {
      setTextColor(color)
      setUnderline()
      setStrikethrough()
  }

which results in "this has many effects" being colored, underlined and strikethrough.

Appending spans

If you wish to append multiple spans, there are supported functions for this in the library.

  spannable(first text") appendSpace spannable("second text")

which simply appends and adds a space character inbetween the two. Resulting in first text second text It is also possible for a line break like so:

  spannable("first text") appendLine spannable("second text on a new line")

results in

  first text
  second text on a new line

What is supported

Running the demo will showcase what is supported. As of right now there is

  • setTextSize
  • setTextSizeDp
  • setTextColor
  • setUnderline
  • setStrikethrough
  • setScale
  • setBold
  • setItalic
  • setBackgroundColor
  • setFont
  • setTextAppearance
  • setClickable

Demo

[]