Change the color of the EditText line and the color of the EditText cursor programmatically for a minimum API level of 14?

I tried the below snippet but did not work below API 21:

editText.getBackground().setColorFilter(editTextColor, PorterDuff.Mode.SRC_IN);
editText.getBackground().mutate().setColorFilter(editTextColor,PorterDuff.Mode.SRC_ATOP);

So please suggest me how can I change for API 14.

+4
source share
2 answers

Use this:

Drawable drawable = editText.getBackground();
drawable.setColorFilter(editTextColor, PorterDuff.Mode.SRC_ATOP);
if(Build.VERSION.SDK_INT > 16) {
    editText.setBackground(drawable);
}else{
    editText.setBackgroundDrawable(drawable);
}
+5
source

Setting the attribute android:textCursorDrawableto @null should result in using android: textColor as the color of the cursor.

The attribute textCursorDrawableis available in API level 12 and above.

0
source

Source: https://habr.com/ru/post/1654533/


All Articles