I have EditText and want to change color PROGRAMMATICALLY on code.
To change color of cursor I use this code.
But how to change color of the circle on EditView PROGRAMMATICALLY on code?

On
try this: change the value in values/colors.xml file
<color name="colorAccent">#263238</color>
change this color code #263238 to your own color code, so that it will be applicable to all the project. Hope this will help you.
On
The below method works for all cursors bubble such as left, right and center. I mean,beside your request, It works for both left and right ones.
You can change that method to only color the center handle by removing the left and right field names in the two arrays.
public static void colorHandles(TextView view, int color) {
try {
Field editorField = TextView.class.getDeclaredField("mEditor");
if (!editorField.isAccessible()) {
editorField.setAccessible(true);
}
Object editor = editorField.get(view);
Class<?> editorClass = editor.getClass();
String[] handleNames = {"mSelectHandleLeft", "mSelectHandleRight", "mSelectHandleCenter"};
String[] resNames = {"mTextSelectHandleLeftRes", "mTextSelectHandleRightRes", "mTextSelectHandleRes"};
for (int i = 0; i < handleNames.length; i++) {
Field handleField = editorClass.getDeclaredField(handleNames[i]);
if (!handleField.isAccessible()) {
handleField.setAccessible(true);
}
Drawable handleDrawable = (Drawable) handleField.get(editor);
if (handleDrawable == null) {
Field resField = TextView.class.getDeclaredField(resNames[i]);
if (!resField.isAccessible()) {
resField.setAccessible(true);
}
int resId = resField.getInt(view);
handleDrawable = view.getResources().getDrawable(resId);
}
if (handleDrawable != null) {
Drawable drawable = handleDrawable.mutate();
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
handleField.set(editor, drawable);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
You will need to use reflection to tint the select handles (bubbles). I wrote the following class this morning:
Example usage:
EditTextTint.java:
Note: This should work from Jelly Bean to Nougat. However, since it uses reflection to get and set private fields this may break in future releases of Android or if a manufacturer has made changes to EditText.