set Color to EditText - Android User Interface

Android examples for User Interface:EditText

Description

set Color to EditText

Demo Code


import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.BackgroundColorSpan;
import android.text.style.CharacterStyle;
import android.widget.EditText;
import java.util.ArrayList;

public class Main{
    public static void setColor(EditText editText, int color,
            ArrayList<int[]> ranges) {
        String text = editText.getText().toString();
        SpannableString spanText = new SpannableString(text);
        for (int[] range : ranges) {
            BackgroundColorSpan markup = new BackgroundColorSpan(color);
            spanText.setSpan(markup, range[0], range[1] + 1,
                    Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        }//www.  ja  v a2s. c  om
        editText.setText(spanText);
    }
}

Related Tutorials