15
15
import android .widget .ProgressBar ;
16
16
import android .widget .RadioButton ;
17
17
import android .widget .SeekBar ;
18
+ import android .widget .TextView ;
18
19
19
20
import com .afollestad .materialdialogs .R ;
20
21
import com .afollestad .materialdialogs .util .DialogUtils ;
21
22
23
+ import java .lang .reflect .Field ;
24
+
22
25
/**
23
26
* Tints widgets
24
27
*/
@@ -112,6 +115,7 @@ public static void setTint(@NonNull EditText editText, @ColorInt int color) {
112
115
} else if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
113
116
editText .setBackgroundTintList (editTextColorStateList );
114
117
}
118
+ setCursorTint (editText , color );
115
119
}
116
120
117
121
public static void setTint (@ NonNull CheckBox box , @ ColorInt int color ) {
@@ -130,4 +134,26 @@ public static void setTint(@NonNull CheckBox box, @ColorInt int color) {
130
134
box .setButtonDrawable (drawable );
131
135
}
132
136
}
133
- }
137
+
138
+ private static void setCursorTint (@ NonNull EditText editText , @ ColorInt int color ) {
139
+ try {
140
+ Field fCursorDrawableRes = TextView .class .getDeclaredField ("mCursorDrawableRes" );
141
+ fCursorDrawableRes .setAccessible (true );
142
+ int mCursorDrawableRes = fCursorDrawableRes .getInt (editText );
143
+ Field fEditor = TextView .class .getDeclaredField ("mEditor" );
144
+ fEditor .setAccessible (true );
145
+ Object editor = fEditor .get (editText );
146
+ Class <?> clazz = editor .getClass ();
147
+ Field fCursorDrawable = clazz .getDeclaredField ("mCursorDrawable" );
148
+ fCursorDrawable .setAccessible (true );
149
+ Drawable [] drawables = new Drawable [2 ];
150
+ drawables [0 ] = editText .getContext ().getResources ().getDrawable (mCursorDrawableRes );
151
+ drawables [1 ] = editText .getContext ().getResources ().getDrawable (mCursorDrawableRes );
152
+ drawables [0 ].setColorFilter (color , PorterDuff .Mode .SRC_IN );
153
+ drawables [1 ].setColorFilter (color , PorterDuff .Mode .SRC_IN );
154
+ fCursorDrawable .set (editor , drawables );
155
+ } catch (Exception e ) {
156
+ e .printStackTrace ();
157
+ }
158
+ }
159
+ }
0 commit comments