Dưới đây là một cách để làm điều này trong tập tin java:
textview.setText(Html.fromHtml("<b>" + title + "</b>" + "<small>" + description + "</small>"));
HOẶC
Sử dụng spans.
Ví dụ:
final SpannableStringBuilder sb = new SpannableStringBuilder("your text here");
// Span to set text color to some RGB value
final ForegroundColorSpan fcs = new ForegroundColorSpan(Color.rgb(158, 158, 158));
// Span to make text bold
final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD);
// Set the text color for first 4 characters
sb.setSpan(fcs, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
// make them also bold
sb.setSpan(bss, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
yourTextView.setText(sb);
Nguồn
2015-11-24 12:19:26
Như thế này: http://stackoverflow.com/questions/4897349/android-coloring-part-of-a -string-using-textview-settext PS: bạn có thể thay đổi màu hoặc bất cứ thứ gì bạn muốn ở đó. Bạn nên google nó nhiều hơn một chút. –
Bạn có nhận được câu trả lời không? – Amy