content: package com.cjj.mousepaint.utils;
  
  import android.content.res.ColorStateList;
  import android.graphics.drawable.Drawable;
  import android.support.v4.graphics.drawable.DrawableCompat;
  import android.widget.EditText;
  import android.widget.TextView;
  
  import java.lang.reflect.Field;
  
  /**
   * Created by Administrator on 2015/10/10.
   */
  public class TintingDrawablesUtil {
  
  //        TintingDrawablesUtil.tintCursorDrawable(et_user_email, getResources().getColor(R.color.et_tinting_color));
  //        et_user_email.setBackgroundDrawable(TintingDrawablesUtil.tintDrawable(et_user_email.getBackground(),
  //                getResources().getColorStateList(R.color.et_tinting_color)));
  
      public static Drawable tintDrawable(Drawable drawable, ColorStateList colors) {
          final Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
          DrawableCompat.setTintList(wrappedDrawable, colors);
          return wrappedDrawable;
      }
  
      /**
       * 光标着色
       * @param editText
       * @param color
       */
      public static void tintCursorDrawable(EditText editText, int color) {
          try {
              Field fCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
              fCursorDrawableRes.setAccessible(true);
              int mCursorDrawableRes = fCursorDrawableRes.getInt(editText);
              Field fEditor = TextView.class.getDeclaredField("mEditor");
              fEditor.setAccessible(true);
              Object editor = fEditor.get(editText);
              Class<?> clazz = editor.getClass();
              Field fCursorDrawable = clazz.getDeclaredField("mCursorDrawable");
              fCursorDrawable.setAccessible(true);
  
              if (mCursorDrawableRes <= 0) {
                  return;
              }
  
              Drawable cursorDrawable = editText.getContext().getResources().getDrawable(mCursorDrawableRes);
              if (cursorDrawable == null) {
                  return;
              }
  
              Drawable tintDrawable  = tintDrawable(cursorDrawable, ColorStateList.valueOf(color));
              Drawable[] drawables = new Drawable[] {tintDrawable, tintDrawable};
              fCursorDrawable.set(editor, drawables);
          } catch (Throwable ignored) {
          }
      }
  }
  