title: Single textview with two different colors for dynamic text
body: <p>I have a textview and I want to change the color of word starting with @ to red color and if there is also word with # , I want to change it to black color.Text is not hard coded. How can I do this.Please help me.I have tried with the below code.but the problem is red color is only applied for the first word.</p>
  
  <pre><code>String MsgTitle = Details.get(position).getContent();
                  String refString;
                  String hashString;
                  if (MsgTitle.contains(" ")) {
                      refString = MsgTitle.substring(0,
                              MsgTitle.indexOf(' ')).trim();
  
                      if (String.valueOf(refString.charAt(0)).equals("@")) {
                          refString = refString.replaceFirst("(^@\\w+)",
                                  "&lt;font color='#8A0A0A'&gt;$1&lt;/font&gt;");
                      } else {
                          refString = refString.replaceAll("(#\\w+)",
                                  "&lt;font color='#000000'&gt;&lt;b&gt;$1&lt;/b&gt;&lt;/font&gt;");
                      }
  
                      hashString = MsgTitle.substring(
                              MsgTitle.indexOf(' ') + 1).trim();
                      ((TextView) vi.findViewById(R.id.textData))
                              .setText(Html.fromHtml(refString
                                      + " "
                                      + hashString
                                              .replaceAll("(#\\w+)",
                                                      "&lt;font color='#000000'&gt;&lt;b&gt;$1&lt;/b&gt;&lt;/font&gt;")));
  }
  </code></pre>
  
  <p><em><strong>Answer for my issue</em></strong></p>
  
  <pre><code>tring[] str_array = str .split(" ");
  
              boolean isExists = false;
              for (int i = 0; i &lt; str_array.length; i++) {
                  for (int j = 0; j &lt; i; j++) {
                      if (str_array[j].equals(str_array[i])) {
                          isExists = true;
                      }
                  }
                  if (str_array[i].startsWith("@") &amp;&amp; !isExists) {
                      str  = str .replace(str_array[i],
                              "&lt;font color='#8A0A0A'&gt;" + str_array[i]
                                      + "&lt;/font&gt;");
                  } else if (str_array[i].contains("#")) {
                      str  = str .replaceAll(str_array[i],
                              "&lt;font color='#000000'&gt;&lt;b&gt;" + str_array[i]
                                      + "&lt;/b&gt;&lt;/font&gt;");
                  }
              }
  </code></pre>