An open API service indexing awesome lists of open source software.

https://github.com/irontec/inkspannable

Better spannable creation.
https://github.com/irontec/inkspannable

Last synced: 7 months ago
JSON representation

Better spannable creation.

Awesome Lists containing this project

README

          

# InkSpannable
[![](https://jitpack.io/v/irontec/InkSpannable.svg)](https://jitpack.io/#irontec/InkSpannable)

Better spannable creation.

## Configuration

First of all you need to pass the Application context to the InkSpannableConfig (as a WeakReference, do not fear):

```kt
class AppCtrl : Application() {

override fun onCreate() {
super.onCreate()

// initialize the singleton
instance = this

InkSpannableConfig.context = WeakReference(this)
}

companion object {

/**
* A singleton instance of the application class for easy access in other places
*/
lateinit var instance: AppCtrl
private set
}
}
```

Then you can create an InkSpannable with some text or empty, and modify it. It has methods available to add text (styled if you want, string or string resource id) or to modify current text style. Then you build it and assign it to a TextView or some other text holder which supports SpannableStringBuilder.

## Example

Build some long text:
```kt
textview.text = InkSpannableBuilder().addText("long")
.addBlank().addTextItalic("long")
.addBlank().addTextBoldItalic("complex")
.addBlank().addTextColor("text", getColorCompat(R.color.basic_red))
.addBlank().addTextColor("I", getColorCompat(R.color.basic_green))
.addBlank().addTextColor("am", getColorCompat(R.color.basic_blue))
.addBlank().addTextUnderline("testing")
.build()
```

Create with text and then modify it:
```kt
textview.text = InkSpannableBuilder(R.string.long_text_1)
.boldText(AppCtrl.instance.resources.getStringArray(R.array.long_text_1_bold).toList())
.build()
```

With resources from strings.xml:
```xml
We define some words to bold on an array in Strings.xml, like this one or this other one

Strings.xml
this one
this other one

```