Java tutorial
//package com.java2s; import android.text.SpannableStringBuilder; import android.text.style.ForegroundColorSpan; import android.widget.TextView; public class Main { /** * Set an error message to a text view * * @param color Set the color foreground for the span * @param message Message to be shown * @param txtView Text View to which the message will be added */ public static void setError(int color, String message, TextView txtView) { ForegroundColorSpan fgcspan = new ForegroundColorSpan(color); SpannableStringBuilder ssbuilder = new SpannableStringBuilder(message); ssbuilder.setSpan(fgcspan, 0, message.length(), 0); txtView.setError(ssbuilder); } }