设置指定文字颜色:
String str = "There are 36 apps in your phone.";
int index = appNum.indexOf("apps");
SpannableStringBuilder ss = new SpannableStringBuilder(str);
ForegroundColorSpan span=new ForegroundColorSpan(Color.parseColor("#F79719"));
ss.setSpan(span,16, index, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(ss)
ss.setSpan(new BackgroundColorSpan(Color.RED),start,end,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
设置指定文字大小:
String param = "abc" ;
String text = param + "dfdjkfjdkfjdfjdkf" ;
SpannableStringBuilder ss = new SpannableStringBuilder(text);
ss.setSpan(new StyleSpan(Typeface.BOLD),0, param.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new AbsoluteSizeSpan(30,true), 0, param.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new AbsoluteSizeSpan(16,true), param.length(), text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(ss);
文字加下划线:
public void underline(int start,int end){
SpannableStringBuilder spannable=new SpannableStringBuilder(getText().toString());
CharacterStyle span=new UnderlineSpan();
spannable.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
setText(spannable);
}
分享到:
相关推荐
A helper class that extends SpannableStringBuilder and adds methods to easily mark the text with multiple spans. Download You can just copy the class to your project or grab it via Gradle: compile '...
SpannableStringBuilder让TextView实现炫酷效果
图文混排,SpannableStringBuilder,stringbuilder的使用
提供SpannableStringBuilder的简单使用,分享给大家,希望能够帮到需要的人!
SpannableStringBuilder 用法demo,仿陌陌表情插入
GridView+SpannableStringBuilder 实现表情展示和TextView显示表情png
博客《SpannableString与SpannableStringBuilder》对应源码,博客地址:http://blog.csdn.net/harvic880925/article/details/38984705
今天稍微整理下SpannableString与SpannableStringBuilder,因为在上篇中,我们曾讲到过有关CharSequence的东东,有关CharSequence的话,这两个类是必谈的,所以这里加以整理。 一、概述 1、SpannableString、...
> Kotlin wrappers around SpannableStringBuilder. Inspired by binaryfork's Spanny. SpannableStringBuilder API is attractive, it's a nice way to styling text without split your text into multiple views,...
使用链式结构组成SpannableStringBuilder。使得结构上更加清晰,使用时更加方便。 使用对比 代码对比: //链式结构 private fun initContentTop() { RichText.Builder(this) .backColor(1, 4, Color.RED) ....
化妆品 Android上SpannableStringBuilder的包装器
NULL 博文链接:https://breaklayer.iteye.com/blog/738596
SpannableStringBuilder builder = new SpannableStringBuilder(); builder.append("2333333n") start = builder.length(); builder.append("[emotion:tv_cheers]"); DraweeSpan span = new DraweeSpan(...
如果你想要在一个TextView显示一个被...因为,Android已经给我封装好了——SpannableStringBuilder。下面我就学习Android中对控件的一些封装来封装一个我们自己的TextView(既可在xml中设置也可在Java代码中设置)。
文本样式设置之SpannableString类的应用
https://blog.csdn.net/hugn215/article/details/81035510
学习SpannableString&&SpannableStringBuilder的资料
SpannableStringBuilder builder = new SpannableStringBuilder (); builder . append( " 2333333 \n " ) start = builder . length(); builder . append( " [emotion:tv_cheers] " ); DraweeSpan span = new ...
EditText结合SpannableStringBuilder,添加图片和自定义文字等实例。