Android examples for User Interface:EditText
set Color to EditText
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); } }