https://github.com/vanniktech/textbuilder
Provides a Class with a builder pattern for building beautiful text super easily. Internally it uses the Spannable API.
https://github.com/vanniktech/textbuilder
android color formatting text textview
Last synced: 6 months ago
JSON representation
Provides a Class with a builder pattern for building beautiful text super easily. Internally it uses the Spannable API.
- Host: GitHub
- URL: https://github.com/vanniktech/textbuilder
- Owner: vanniktech
- License: apache-2.0
- Created: 2017-01-24T21:57:52.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2025-06-24T20:44:44.000Z (7 months ago)
- Last Synced: 2025-06-24T21:41:22.441Z (7 months ago)
- Topics: android, color, formatting, text, textview
- Language: Java
- Homepage:
- Size: 809 KB
- Stars: 18
- Watchers: 3
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/funding.yml
- License: LICENSE
Awesome Lists containing this project
README
TextBuilder
===========
Provides a Class with a builder pattern for building beautiful text super easily. Internally it uses the Spannable API.
```java
new TextBuilder(this) // Context
.addText(R.string.some_text)
.addWhiteSpace()
.addColoredTextRes("in green", R.color.green)
.addWhiteSpace()
.addColoredText("and blue", Color.BLUE)
.addWhiteSpace()
.into(textView);
```
Also certain parts of a text can be formatted:
```java
new TextBuilder(this) // Context
.addFormableText("Terms of use and privacy terms")
.format("Terms of use")
.textColor(Color.RED)
.italic()
.bold()
.clickable(() -> Log.d(TAG, "Clicked on Terms of Use"))
.done()
.format("privacy terms")
.underline()
.bold()
.clickable(() -> Log.d(TAG, "Clicked on Privacy Terms"))
.done()
.into(textView);
```
Displaying images is also not a problem:
```java
new TextBuilder(this)
.addDrawable(R.drawable.ic_done_black_18dp)
.addWhiteSpace()
.addText("Shopping")
.addNewLine()
.addText("Cleaning")
.into(textView);
```
For now only the basic things are supported and some features may be lacking. I'm open for any suggestions or new APIs.
# Setup
**build.gradle**
```groovy
compile 'com.vanniktech:textbuilder:0.4.0'
compile 'com.vanniktech:textbuilder:0.5.0-SNAPSHOT'
```
Modules are located on [Maven Central](https://oss.sonatype.org/#nexus-search;quick~textbuilder).
# Proguard
No configuration needed.
# License
Copyright (C) 2017 Vanniktech - Niklas Baudy
Licensed under the Apache License, Version 2.0