Set EditText cursor color
For anyone that needs to set the EditText cursor color dynamically, below you will find two ways to achieve this. First, create your cursor drawable: Set the cursor drawable resource id to the drawable you created (...
Technical answers from my Stack Overflow history, with source links and licenses.
Showing 6 of 6 answers tagged android-edittext
Exported May 9, 2026
For anyone that needs to set the EditText cursor color dynamically, below you will find two ways to achieve this. First, create your cursor drawable: Set the cursor drawable resource id to the drawable you created (...
Update 2019: There is no public API to set the cursor drawable. See https://stackoverflow.com/a/57555148/253468 for API available on 29 and above, before that conditionally you'll need to use reflection as described...
How to do it from code:
As @CommonsWare pointed out, what you are doing should be OK. It is impossible to guarantee disabled auto-capitalization across all devices. If the user is using a third-party keyboard, like SwiftKey, it may override...
You can accomplish this by using a custom theme and setting the following: Or, you can use reflection:
If I remove all spans before setting the new ForegroundColorSpan then I get the desired behavior. Unfortunately, this is a lot more work if an EditText has a lot of text. What I did for a fix: I'm not sure what changed...