diff options
author | Aidan Follestad <drummer.aidan@gmail.com> | 2016-01-08 10:39:18 -0600 |
---|---|---|
committer | Aidan Follestad <drummer.aidan@gmail.com> | 2016-01-08 10:39:18 -0600 |
commit | 0067805352102164bb744fc7ba4036965b0bd45e (patch) | |
tree | bb21e8e90fdc0937d5a7cbf44ce7f065380d2d84 | |
parent | 47b115f344ba5c105fd984b3297527d4142203ce (diff) | |
download | afollestad-0067805352102164bb744fc7ba4036965b0bd45e.tar.gz |
TintHelper can tint cursor of EditTexts.
-rw-r--r-- | core/src/main/java/com/afollestad/materialdialogs/internal/MDTintHelper.java | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/core/src/main/java/com/afollestad/materialdialogs/internal/MDTintHelper.java b/core/src/main/java/com/afollestad/materialdialogs/internal/MDTintHelper.java index 2b8a2d2..e4c075c 100644 --- a/core/src/main/java/com/afollestad/materialdialogs/internal/MDTintHelper.java +++ b/core/src/main/java/com/afollestad/materialdialogs/internal/MDTintHelper.java @@ -15,10 +15,13 @@ import android.widget.EditText; import android.widget.ProgressBar; import android.widget.RadioButton; import android.widget.SeekBar; +import android.widget.TextView; import com.afollestad.materialdialogs.R; import com.afollestad.materialdialogs.util.DialogUtils; +import java.lang.reflect.Field; + /** * Tints widgets */ @@ -112,6 +115,7 @@ public class MDTintHelper { } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { editText.setBackgroundTintList(editTextColorStateList); } + setCursorTint(editText, color); } public static void setTint(@NonNull CheckBox box, @ColorInt int color) { @@ -130,4 +134,26 @@ public class MDTintHelper { box.setButtonDrawable(drawable); } } -} + + private static void setCursorTint(@NonNull EditText editText, @ColorInt 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); + Drawable[] drawables = new Drawable[2]; + drawables[0] = editText.getContext().getResources().getDrawable(mCursorDrawableRes); + drawables[1] = editText.getContext().getResources().getDrawable(mCursorDrawableRes); + drawables[0].setColorFilter(color, PorterDuff.Mode.SRC_IN); + drawables[1].setColorFilter(color, PorterDuff.Mode.SRC_IN); + fCursorDrawable.set(editor, drawables); + } catch (Exception e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file |