Skip to content

sz32/CustomSpanStrings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

CustomSpanStrings

CustomSpanString is a class which you can use for applying multiple spans in single textview the spans you can use for Bold, Underline, Color and Clickable

Usage

val greeting = "Hello"
val name = "SpannableString"

// Important: Set final text in textView before using CustomSpanStrings
val title = "$greeting, $name"
textView.text = title

CustomSpanStrings.withTextView(textView)
    .addClickListener(name) {
        // Do something when $name is clicked
    }
    .applyBold(name) // To apply bold to $name
    .applyUnderline(name) // To apply underline to $name
    .applyColor(Color.GRAY, name) // To change color of $name
    .applyColor(Color.LTGRAY, greeting) // To change color of $greeting
    .commit() // Finally commit all changes

Initialize

To initialize SpannableStringBuilder using the text from textView

CustomSpanStrings.withTextView(textView)

Clickable

To add click listener to $name text.

.addClickListener(name) {
    // Do something when $name is clicked
}

Bold

To apply bold to $name text. You can pass multiple texts to apply bold effect to the texts.

.applyBold(name)

Underline

To apply underline to $name text. You can pass multiple texts to apply underline effect to the texts.

.applyUnderline(name)

Color

To apply grey color to $name text. You can pass multiple texts to apply same color to the texts.

.applyColor(Color.GRAY, name)

Commit

For applying all spans and set to your textview

.commit()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages