Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two colors of text in Android progress dialog message

I have a progress dialog and I want to display text message like below

  1. Downloading
  2. Decompressing

Can I display "1. Downloading" in green and "2. Decompressing" red. where as my code is

mProgressDialog.setMessage("1. Downloading \n 2. Decompressing");
like image 908
sHa Xahid Avatar asked Dec 18 '25 00:12

sHa Xahid


1 Answers

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);
like image 69
Chirag Avatar answered Dec 20 '25 12:12

Chirag