点击打开链接http://blog..net/asdf717/article/details/51499027
上面这个链接是之前了解的我当时已知的改变textView颜色的方法
今天好像有发现了一中,特拿里分享
TextView textView = (TextView) findViewById(R.id.textView);
String str1 = \”你猜1我猜1大家都猜1\”;
String str2 = \”嘻嘻哈哈,啊啊啊啊,唔哈呜哈\”;
Color color = new Color();
SpannableString spanttt = new SpannableString(str1);
ClickableSpan clickstr1 = new MyClickableSpan(color.rgb(255, 255, 0),
this);
spanttt.setSpan(clickstr1, 0, str1.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
SpannableString spansss = new SpannableString(str2);
ClickableSpan clickstr2 = new MyClickableSpan(color.rgb(0, 0, 255),
this);
spansss.setSpan(clickstr2, 0, str2.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(\”我是谁\”);
textView.append(spanttt);
textView.append(\”你是谁你是谁你是谁你是谁你是谁你是谁你是谁\”);
textView.append(spansss);
textView.setMovementMethod(LinkMovementMethod.getInstance());
public class MyClickableSpan extends ClickableSpan {
String string;
Context context;
int color;
int bgcolor;
public MyClickableSpan(String str, Context context) {
super();
this.string = str;
this.context = context;
}
public MyClickableSpan(int color, Context context) {
super();
this.color = color;
this.context = context;
}
public MyClickableSpan(int color, int bgcolor, Context context) {
super();
this.color = color;
this.bgcolor = bgcolor;
this.context = context;
}
@Override
public void updateDrawState(TextPaint ds) {
// 设置可点击文字的颜色值:注意这地方的参数是id或rgb值,
// 如果设置R.color.blue等自定义的颜色值时不会出现预想的效果
//ds.setColor(color);
// ds.setColor(Color.BLUE);//设置颜色值有效
// ds.setColor(R.color.red);//设置颜色值“无效”
//设置可点击文字下面是否带下划线
ds.setUnderlineText(true);
// ds.clearShadowLayer();
}
@Override
public void onClick(View v活动:慈云数据爆款香港服务器,CTG+CN2高速带宽、快速稳定、平均延迟10+ms 速度快,免备案,每月仅需19元!! 点击查看iew) {
// 设置可点击文字的背景色
if (view instanceof TextView)
((TextView) view).setHighlightColor(Color.rgb(253, 65, 65));
// Intent intent = new Intent();
// intent.setClass(context, TwoActivity.class);
// context.startActivity(intent);
}
}
Demo 下载地址
48563666
《androidtextview字体颜色变浅,androidtextview设置字体样式》来自互联网同行内容,若有侵权,请联系我们删除!
还没有评论,来说两句吧...