SpannableTextView 是一个自定义的 TextView,它允许您通过 Spannable 来自定义文本或语句的格式,但无需像使用 SpannableString 那样麻烦。
SpannableTextView 是一个自定义的 TextView,它允许您通过 Spannable 来自定义文本或语句的格式,但无需像使用 SpannableString 那样麻烦。
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.repositories {
maven { url 'https://dl.bintray.com/milaptank/SpannableTextView' }
}
dependencies{
compile 'com.milaptank:stv:1.0.0'
}Examples of different styles. Each one is a single TextView.
Generate the following style:
With the code below:
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();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 |
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:
// 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();…All pull requests are welcome.
暂无开放 Issues,或尚未同步最近议题。