SpannableTag is an Android library that simplifies the usage of the Spannable library by allowing developers to use custom tags in strings. The library parses these tags and applies the corresponding spannable styles to the text.
- Foreground Color: Apply custom foreground colors using hex codes. For example,
<c#ff0000>red text</c#ff0000>
will make "red text" appear in red. - Background Color: Apply custom background colors using hex codes. For example,
<bg#00ff00>green background</bg#00ff00>
will make "green background" text have a green background. - Bold: Make text bold. For example,
<b>bold text</b>
will make "bold text" bold. - Italic: Make text italic. For example,
<i>italic text</i>
will make "italic text" italic. - Underline: Underline text. For example,
<u>underlined text</u>
will underline "underlined text". - Strikethrough: Apply strikethrough to text. For example,
<strike>strikethrough text</strike>
will add a strikethrough to "strikethrough text". - Text Size: Set custom text sizes. For example,
<size.2>large text</size.2>
will make "large text" have a size of 2.
Add the following dependency to your build.gradle
file:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.YosiBs:SpannableTag-Android-Library:Tag'
}
To use the SpannableTag library, follow these steps:
import com.example.spannabletag.SpannableParser;
import android.text.SpannableString;
String text = "hello world";
SpannableString spannableString = SpannableParser.parse(text);
textView.setText(spannableString);
Tag | Description | Example |
---|---|---|
<b></b> | Bold text | <b>bold text</b> |
<i></i> | Italic text | <i>italic text</i> |
<u></u> | Underline text | <u>underline text</u> |
<strike></strike> | Strikethrough text | <strike>strikethrough text</strike> |
<size.{value}></size.{value}> | Set text size | <size.2>large text</size.2> |
<c#{hex}></c#{hex}> | Set text color using hex code | <c#ff0000>red text</c#ff0000> |
Input:
Output:
SpannableTag is licensed under the MIT License. See the LICENSE
file for more information.