百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

SpannableTextView

> 编程语言
开源

SpannableTextView 是一个自定义的 TextView,它允许您通过 Spannable 来自定义文本或语句的格式,但无需像使用 SpannableString 那样麻烦。

197 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

SpannableTextView 是一个自定义的 TextView,它允许您通过 Spannable 来自定义文本或语句的格式,但无需像使用 SpannableString 那样麻烦。

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javaandroidjavalibraryspannable

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

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