Change the color of the Cursor of TextInputEditText from the code without using Reflection.
I have tried this:
val fCursorDrawableRes = TextView::class.java.getDeclaredField("mCursorDrawableRes")
fCursorDrawableRes.isAccessible = true
val mCursorDrawableRes = fCursorDrawableRes.getInt(editText)
val fEditor = TextView::class.java.getDeclaredField("mEditor")
fEditor.isAccessible = true
val editor = fEditor.get(editText)
val clazz = editor.javaClass
val fCursorDrawable = clazz.getDeclaredField("mCursorDrawable")
fCursorDrawable.isAccessible = true
val drawables = arrayOfNulls<Drawable>(2)
drawables[0] = editText.context.resources.getDrawable(mCursorDrawableRes)
drawables[1] = editText.context.resources.getDrawable(mCursorDrawableRes)
drawables[0]!!.setColorFilter(color, PorterDuff.Mode.SRC_IN)
drawables[1]!!.setColorFilter(color, PorterDuff.Mode.SRC_IN)
fCursorDrawable.set(editor, drawables)
This works fine for Android version < 9.0, with the version 9 they have used @UnsupportedAppUsage for the mCursorDrawableRes, and hence not able to access it. Is there any other way to do it?