Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

SpannableTextView

> 编程语言
Open source

SpannableTextView is a custom TextView which lets you customize the styling of slice of your text or statment via Spannables, but without the hassle of having t

197 stars0 likes0 views
WebsiteGitHub

About

SpannableTextView is a custom TextView which lets you customize the styling of slice of your text or statment via Spannables, but without the hassle of having t

SpannableTextView is a custom TextView which lets you customize the styling of slice of your text or statment via Spannables, but without the hassle of having to deal directly with Spannable themselves.

Add this in your build.gradle

groovy
repositories {
    maven { url 'https://dl.bintray.com/milaptank/SpannableTextView' }
}
dependencies{
   compile 'com.milaptank:stv:1.0.0'
}

What can I do with SpannableTextView?

Examples of different styles. Each one is a single TextView.

Example

Generate the following style:

With the code below:

java
SpannableTextView stvMarksDown = findViewById(R.id.stvMarksDown);
 stvMarksDown.addSlice(new Slice.Builder("  3.5/10  ")
                .backgroundColor(Color.parseColor("#800736"))
                .textColor(Color.WHITE)
                .setCornerRadius(13)
                .build());
        stvMarksDown.addSlice(new Slice.Builder(" horrible! ")
                .textColor(Color.parseColor("#073680"))
                .style(Typeface.BOLD)
                .build());
        stvMarksDown.display();

What kind of styles can I add?

Right now you can customize the style of your text by using the following methods, which internally get converted to the corresponding Spannables

SpannableTextView Internal Span
textSize AbsoluteSizeSpan
textColor ForegroundColorSpan
textSizeRelative RelativeSizeSpan
backgroundColor BackgroundColorSpan
style StyleSpan
underline UnderlineSpan
strike StrikethroughSpan
superscript SuperscriptSpan
subscript SubscriptSpan
setCornerRadius RoundedBackgroundSpan(Custom)
setImageResource ImageSpan

What else can I do?

Once you've created and displayed your SpannableTextView, you can modify the text contents of each Slice individually. For example, if we want to change the 3.5/10 from the above example into 6/10, we could do the following:

java
// grab the Slice at position 1
Slice slice = stvMarksDown.getSlice(1);
// modify it's text
slice.setText("6/10");
// you must always call display after you alter a Slice's text
stvMarksDown.display();

License

…

Contributing to SpannableTextView

All pull requests are welcome.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javaandroidjavalibraryspannable

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言