Reputation: 101
I have a progress dialog and I want to display text message like below
Can I display "1. Downloading" in green and "2. Decompressing" red. where as my code is
mProgressDialog.setMessage("1. Downloading \n 2. Decompressing");
Upvotes: 3
Views: 1658
Reputation: 14367
I think you can use HTML in set message - it works for Alert and text views - I havent tried for progress dialog but try it.To give you an idea here's some code - just modify it to suit your requirements
Basically
In your strings.xml
<string name="downloading"><![CDATA[<font color="green">1.Downloading</font><br/>]]></string>
<string name="decompressing"><![CDATA[<font color="red">2.Decompressing</font><br/>]]></string>
And call
mProgressDialog.setMessage(Html.fromHtml(getString(R.string.downloading))+""+ Html.fromHtml(getString(R.string.decompressing)));
Upvotes: 4
Reputation: 56925
Look at this code.
final SpannableStringBuilder sb = new SpannableStringBuilder("your text here");
final ForegroundColorSpan fcs = new ForegroundColorSpan(Color.rgb(158, 158, 158));
// Span to set text color to some RGB value
final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD);
// Span to make text bold
sb.setSpan(fcs, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
// Set the text color for first 4 characters
sb.setSpan(bss, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
// make them also bold
yourTextView.setText(sb);
Upvotes: 5