public static void setTint(@NonNull EditText editText, @ColorInt int color, boolean useDarker) { final ColorStateList editTextColorStateList = new ColorStateList(new int[][]{ new int[]{-android.R.attr.state_enabled}, new int[]{android.R.attr.state_enabled, -android.R.attr.state_pressed, -android.R.attr.state_focused}, new int[]{} }, new int[]{ ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_text_disabled_dark : R.color.ate_text_disabled_light), ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light), color }); if (editText instanceof TintableBackgroundView) { ViewCompat.setBackgroundTintList(editText, editTextColorStateList); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { editText.setBackgroundTintList(editTextColorStateList); } setCursorTint(editText, color); }
public static void setTint(@NonNull EditText editText, @ColorInt int color, boolean useDarker) { final ColorStateList editTextColorStateList = new ColorStateList(new int[][]{ new int[]{-android.R.attr.state_enabled}, new int[]{android.R.attr.state_enabled, -android.R.attr.state_pressed, -android.R.attr.state_focused}, new int[]{} }, new int[]{ ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_disabled_edittext_dark : R.color.ate_disabled_edittext_light), Util.resolveColor(editText.getContext(), R.attr.colorControlNormal), color }); if (editText instanceof AppCompatEditText) { ((AppCompatEditText) editText).setSupportBackgroundTintList(editTextColorStateList); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { editText.setBackgroundTintList(editTextColorStateList); } }
/** * Tint an {@link EditText} by changing its cursor, hint, etc. colors according to the * supplied color. * * @param editText The edit text to be colorized. * @param color The color to be used. */ public static void setColor(@NonNull EditText editText, @ColorInt int color) { ColorStateList editTextColorStateList = DynamicResourceUtils.getColorStateList(color); if (editText instanceof TintableBackgroundView) { ViewCompat.setBackgroundTintList(editText, editTextColorStateList); } else if (DynamicVersionUtils.isLollipop()) { editText.setBackgroundTintList(editTextColorStateList); } setCursorColor(editText, color); }
public static void setTint(@NonNull EditText editText, @ColorInt int color, boolean useDarker) { final ColorStateList editTextColorStateList = new ColorStateList(new int[][]{ new int[]{-android.R.attr.state_enabled}, new int[]{android.R.attr.state_enabled, -android.R.attr.state_pressed, -android.R.attr.state_focused}, new int[]{} }, new int[]{ ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_text_disabled_dark : R.color.ate_text_disabled_light), ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light), color }); if (editText instanceof AppCompatEditText) { ((AppCompatEditText) editText).setSupportBackgroundTintList(editTextColorStateList); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { editText.setBackgroundTintList(editTextColorStateList); } setCursorTint(editText, color); }