Android TextView里显示两种颜色

今天介绍一个小技巧,在Android的TextView里设置两种颜色,直接上代码:

 TextView TV = (TextView)findViewById(R.id.mytextview01);
Spannable WordToSpan = new SpannableString("Your message"); WordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 0, WordToSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); TV.setText(WordToSpan);
Spannable WordToSpan1 = new SpannableString("Your new message"); WordToSpan1.setSpan(new ForegroundColorSpan(Color.RED), 0, WordToSpan1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TV.append(WordToSpan1);
上一篇:java – 代码太大,常量错误太多(Android Studio)


下一篇:关于表格table嵌套,边框合并问题的解决方法,table嵌套(转)