[Android&iOS]改变特定文字颜色

来源:互联网 发布:大数据行业现状 编辑:程序博客网 时间:2024/05/17 03:49

iOS

NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]initWithString:@"This is Gray"];[attrString addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(7, 4)];Label.attributedText = attrString;

Android

SpannableStringBuilder style = new SpannableStringBuilder("This is Gray");style.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.gray)),7,4,Spannable.SPAN_EXCLUSIVE_INCLUSIVE); TextView.setText(style);
0 0
原创粉丝点击