SpannableStringBuilder的使用方法
2014-03-31 17:42
232 查看
SpannableStringBuilder的使用方法
package com.example.helloworld;import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
//import android.text.Html;
import android.widget.TextView;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
//import android.text.SpannableString;
//import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv=(TextView)findViewById(R.id.textview); --创建一个textview控件
String str="thisismyfirst class";--声明一个字符串变量
SpannableStringBuilder style=new SpannableStringBuilder(str); 将str字符串载入SpannableStringBuilder对象中
--分段显示str字符串的字体的颜色,ForegroundColorSpan(Color.RED)表示是1,到4这个范围内的字符的颜色是红色,
--SPAN_EXCLUSIVE_INCLUSIVE 表示1到4这个范围内的字符不包含第一个但是包含第4个字符,也就是从第二个字符开始到第四个字符,他的颜色都是红色
style.setSpan(new ForegroundColorSpan(Color.RED), 1, 4, Spannable.SPAN_EXCLUSIVE_INCLUSIVE); style.setSpan(new ForegroundColorSpan(Color.BLUE), 5, 7, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
tv.setText(style);
}
}
相关文章推荐
- SpannableStringBuilder的使用方法
- EditText控件的使用续:Editor实现类SpannableStringBuilder实现的Spanned和Spannable接口方法
- SpannableStringBuilder的使用方法
- SpannableStringBuilder的setSpan方法使用需注意点!
- SpannableStringBuilder的使用方法
- SpannableStringBuilder的使用方法
- java 中String和StringBuffer与StringBuilder的区别及使用方法
- 使用android SpannableStringBuilder实现图文混排,查看更多
- SpannableStringBuilder的使用
- 聊天记录,踩的坑:设置EditText焦点;EditText软键盘和recyclerview的交互;SpannableStringBuilder的使用;ClickableSpan失效;软键盘挡住edi
- java学习之旅57、58--数组_StringBuilder和StringBuffer的使用_JDK源码分析内部机制、常用方法补充_常见面试题答法
- 朝花夕拾:Java中String,StringBuffer,StringBuilder使用方法以及异同比较
- (第三季)101-字符串类string基础使用102-字符串类string更多的方法103-字符串类StringBuilder的构造 104-string和StringBuilder的区别105-St
- SpannableStringBuilder使用方式与介绍
- 在StringBuffer(StringBuilder)的append()方法中使用加号是否合适?
- TextView使用小技巧——一个TextView多重属性设置(SpannableStringBuilder)
- (一)SpannableString、SpannableStringBuilder的简单使用
- 数组第二十三课,StringBuilder和StringBuffer的使用,常用方法
- 使用android SpannableStringBuilder实现图文混排,看到许多其他
- StringBuilder 使用方法