Reputation: 3322
I am using like this it should show green color but showing black
all rgb values are dynamic(web service) same code working in browser(W3 SCHOOLS)
mytextview.setText(Html
.fromHtml("<font style=\"color: rgb(102, 204, 0);\">REGISTRATION</font>"));
Upvotes: 0
Views: 1608
Reputation: 16214
Where are you writing that "REGISTRATION" is green?
String hex = String.format("#%02x%02x%02x", r, g, b);
String html = String.format("<font color='%s'>REGISTRATION</font>",hex);
mytextview.setText(Html.fromHtml(html));
Upvotes: 1
Reputation: 47817
try this
String formattedText = "This is <font color='#659D32'>green</font>";
textElement.setText(Html.fromHtml(formattedText));
Or another way is using SpannableStringBuilder
String registration = "REGISTRATION";
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(registration);
ForegroundColorSpan colorSpannable = new ForegroundColorSpan(Color.rgb(102, 204, 0));
spannableStringBuilder.setSpan(colorSpannable, 0, registration.length()-1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
mytextview.setText(spannableStringBuilder);
Upvotes: 1
Reputation: 5672
mytextview.setText(Html.fromHtml("<![CDATA[<font color='#659D32'>REGISTRATION</font>]]>"));
Or use SpannableStringBuilder:
String text = "REGISTRATION";
SpannableStringBuilder span = new SpannableStringBuilder(text);
span.setSpan(new ForegroundColorSpan(Color.parseColor("#659D32")), 0, text.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
mytextview.setText(span);
Upvotes: 0