Q:

Change text color in EditText

I am learning how to make a syntax highlighter. What I would like to ask is how I can change the text color of some part of the text and leave the rest in default color ?  
What I mean is doing something similar to what most IDEs do; they highlight they keywords and let the others be in black color.  
How can this be done in Android EditText, or some other view?

A:

If you want to make the 'EditText' behave like an IDE (i.e. eclipse) then you need to define a list of words that you want to be in different color then add a function like this:
EditText et = new  EditText(mContext);
et.addTextChangedListener(new TextWatcher() {

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub

    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // TODO Auto-generated method stub

    }

    @Override
    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub

    }
});

Then use the 'spanable' class to color your key words:
Spannable wordtoSpan = new SpannableString("I know just how to whisper, And I know just how to cry,I know just where to find the answers");        

wordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 15, 30, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
et.setText(wordtoSpan);

You will need to implement some logic to find the starting and ending index of your key words and then iterate over the string to set the color of each item you want. 

