Skip to content

Commit

Permalink
Theming: Fix Cursor color with Android Material 1.8.0 and later. (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech authored Feb 25, 2023
1 parent 71689f4 commit c4a17e7
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,21 @@ internal fun TextView.setHandlesColor(@ColorInt color: Int) {
}
}

private class CursorDrawable(@ColorInt color: Int) : GradientDrawable(Orientation.BOTTOM_TOP, intArrayOf(color, color)) {
override fun setTint(tintColor: Int) {
// No-op https://github.com/material-components/material-components-android/issues/3255#issuecomment-1442269086
}

override fun setTintList(tint: ColorStateList?) {
// No-op https://github.com/material-components/material-components-android/issues/3255#issuecomment-1442269086
}
}

// https://stackoverflow.com/a/59269370/1979703
@SuppressLint("PrivateApi")
internal fun TextView.setCursorDrawableColor(@ColorInt color: Int) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
textCursorDrawable = GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, intArrayOf(color, color))
textCursorDrawable = CursorDrawable(color)
.apply { setSize(2.spToPx(context).toInt(), textSize.toInt()) }
return
}
Expand Down

0 comments on commit c4a17e7

Please sign in to comment.