Reputation: 959
So, i've searched a lot but i couldn't find anything, if this ends up being a duplicate i'm sorry, but i want to cange the color of the EditText's cursor pointer that is used to move the cursor
I already managed to change the cursor's color itself but it doesn't affect the pointer which seems to only respond to accentColor.
I'm pretty sure it's possible because i recall seeing an app that did it, it had the pointer and all the elements in a dialog change color based on a color that you choose without changing the accent color of the view below the dialog.
Please help :)
Upvotes: 10
Views: 9843
Reputation: 21
You can add colorControlActivated to your AppTheme in style :
<item name="colorControlActivated">"Your_color"</item>
Upvotes: 2
Reputation: 3629
You can use reflection to set selectHandle.
EditText has Editor class that has the mSelectHandleCenter field (if you need selection use mSelectHandleLeft and mSelectHandleRight)
private fun setCursorPointerColor(view: EditText, @ColorInt color: Int) {
try {
//get the pointer resource id
var field = TextView::class.java.getDeclaredField("mTextSelectHandleRes")
field.isAccessible = true
val drawableResId = field.getInt(view)
//get the editor
field = TextView::class.java.getDeclaredField("mEditor")
field.isAccessible = true
val editor = field.get(view)
//tint drawable
val drawable = ContextCompat.getDrawable(view.context, drawableResId)!!
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN)
//set the drawable
field = editor.javaClass.getDeclaredField("mSelectHandleCenter")
field.isAccessible = true
field.set(editor, drawable)
} catch (ex: Exception) {
}
}
Upvotes: 2
Reputation: 497
you can use textSelectHandle to replace it by your drawable like this:
android:textSelectHandle="@drawable/your_drawble"
Upvotes: 2
Reputation: 423
You can do this by creating new style in style.xml like this
<style name="CustomEditTextTheme" parent="TextAppearance.AppCompat">
<item name="colorAccent">@color/primary_dark_material_dark</item>
</style>
Then in EditText tag use this
style="@style/CustomEditTextTheme"
Upvotes: 4
Reputation: 2117
You can create your own style/theme for only this EditText and change the ColorAccent :
<style name="EditTextColorCustom" parent="@style/AppBaseTheme">
<!-- Customize your theme here. -->
<item name="colorAccent">@color/colorAccent</item>
</style>
Upvotes: 7