0

I am trying to make an app that summarizes text, and passes that text into a string. From here I split the string word by word, and search for particular words. Ideally, I would like particular words to be capitalized and colored red. However, all of the tutorials I find show how to change the color of the String as a whole. Here is my code:

public void convertToNotes() {
    String conversionText;
    TextView  verifyTextView;



    classNotes=(EditText)findViewById(R.id.class_notes);
    className=(EditText)findViewById(R.id.class_name);
    verifyTextView = (TextView) findViewById(R.id.textView);
    verifyTextView.setSingleLine(false);
    conversionText = classNotes.getText().toString();
    String[] result = conversionText.split("//n");
    String important = "<font color=#00aeef>"+"IMPORTANT" + "</font>";
    important.toUpperCase();


    // tried to load premade textview w/ styling. Threw null pointer exception important_replace = (TextView)findViewById(R.id.important_replacement);
    //String important_detected = important_replace.toString();

    for (int a = 0; a < result.length; a++) {
        // You may want to check for a non-word character before blindly
        // performing a replacement
        // It may also be necessary to adjust the character class
        result[a] = result[a].replaceAll("sorry", "");
        result[a] = result[a].replaceAll("uh", "");
        result[a] = result[a].replaceAll("um", "");
        result[a] = result[a].replaceAll("haha", "");
        result[a] = result[a].replaceAll("nevermind", "");

         result[a] = result[a].replaceAll("important", " \n" + Html.fromHtml(important));

        verifyTextView.setText(Arrays.toString(result));
    }





}

The capitalization words perfectly, however the textColor is still Black.

Ethan
  • 225
  • 2
  • 13
  • Have a look at this answer. Spannable is the way to go. http://stackoverflow.com/questions/3282940/set-color-of-textview-span-in-android – Ivan Wooll Jan 18 '15 at 19:44

1 Answers1

0
String important = "important";
SpannableString mySpannableString = new SpannableString(important .toUpperCase());//uppercase
mySpannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#f00")), 0, format.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);//make it red
tv.setText(mySpannableString);//set formatted text
deadfish
  • 11,996
  • 12
  • 87
  • 136