SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
SpannableString string = new SpannableString("GFDTH");
//给textView设置颜色
stringBuilder.append(Html.fromHtml("<font color='#ff0000'>" + "恭喜"
+ "</font>" + "<font color='#00ff00'>" + "GFDTH" + "</font>"
+ "<font color='#0000ff'>" + "获得了" + "</font>"));
//在textView里手动添加图片
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ImageSpan imageSpan = new ImageSpan(this, bitmap);
string.setSpan(imageSpan, 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
代码的链接:http://download.youkuaiyun.com/detail/how_old/9530407
本文介绍如何使用Android中的TextView实现富文本显示效果,包括不同颜色的文字以及如何在文字中插入图片。通过示例代码展示了具体实现过程。
154

被折叠的 条评论
为什么被折叠?



