Android之修改部分字体颜色

时间:2023-03-09 14:58:36
Android之修改部分字体颜色

#01# 方法一:

            TextView textView = (TextView) view.findViewById(R.id.text);

            SpannableString ss = new SpannableString("北京欢迎你,荣昌挺好的");
ss.setSpan(new ForegroundColorSpan(Color.RED), 0, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new ForegroundColorSpan(Color.GREEN), 7, 10, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(ss);

#02# 方法二:

textView.setText(Html.fromHtml("<font size=\"3\" color=\"red\">北京欢迎你,荣昌挺好的</font><font size=\"3\" color=\"green\">,挺好的</font>"));