当前位置: 代码迷 >> Android >> Android TextView 设立超链,设置部分字体颜色
  详细解决方案

Android TextView 设立超链,设置部分字体颜色

热度:59   发布时间:2016-05-01 19:20:12.0
Android TextView 设置超链,设置部分字体颜色

Android TextView 设置超链

?

? ??android:autoLink="web"

??? android:autoLink="web|email|phone"

?? ?android:autoLink="all"

?

Android TextView 设置部分字体颜色

?

方法一:

?????? SpannableStringBuilder fontStyleBuilder=new SpannableStringBuilder(textString);
??????? fontStyleBuilder.setSpan(new ForegroundColorSpan(Color.RED), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
??????? fontStyleBuilder.setSpan(new ForegroundColorSpan(Color.GREEN), 3, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
??????? fontStyleBuilder.setSpan(new ForegroundColorSpan(Color.BLUE), 5, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
??????? textView.setText(fontStyleBuilder);

?

方法二:

?

??????? textView.setText(Html.fromHtml("测试<font color=red >文字</font>"));

?

  相关解决方案