https://github.com/irontec/inkspannable
Better spannable creation.
https://github.com/irontec/inkspannable
Last synced: 7 months ago
JSON representation
Better spannable creation.
- Host: GitHub
- URL: https://github.com/irontec/inkspannable
- Owner: irontec
- License: gpl-3.0
- Created: 2019-08-16T07:58:48.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-09-14T15:04:21.000Z (over 4 years ago)
- Last Synced: 2025-01-31T04:53:53.301Z (over 1 year ago)
- Language: Kotlin
- Size: 178 KB
- Stars: 1
- Watchers: 6
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# InkSpannable
[](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
```