The TextModifier library provides a simple and efficient way to modify immutable text for markup in Android applications using Kotlin.
- Modify immutable text with ease.
- Apply styles like bold, italic, underline, and strikethrough.
- Change text color and background color.
- Adjust font size.
- Combine multiple styles seamlessly.
To use the TextModifier library in your project, add the following dependency to your build.gradle
file:
implementation "com.pinu.textlibrary:textmodifier:1.0.0"
To use the TextModifier
class, access its singleton instance:
val textModifier = TextModifier.instance
val boldText = textModifier.makeBold("This is bold text")
val italicText = textModifier.makeItalic("This is italic text")
val underlinedText = textModifier.underlineText("This is underlined text")
val strikethroughText = textModifier.strikeThroughText("This is strikethrough text")
val coloredText = textModifier.changeTextColor(context, "This is colored text", R.color.my_color)
val resizedText = textModifier.changeTextSize("This is resized text", 20f)
val styledText = textModifier.applyMultipleStyles(
context,
text = "Styled Text",
isBold = true,
isItalic = true,
isUnderline = true,
colorResId = R.color.my_color,
sizeInSp = 18f
)
Here’s a complete example:
val textModifier = TextModifier.instance
val styledText = textModifier.applyMultipleStyles(
context,
text = "Example Styled Text",
isBold = true,
isItalic = true,
isUnderline = true,
isStrikeThrough = true,
colorResId = R.color.teal_200,
sizeInSp = 24f
)
textView.text = styledText
Check another README of creating android library here : https://github.com/PanktiSP13/TextLibrary-Publish-your-library/blob/main/CREATE_LIBRARY_README.md