I know how to set a drawable as the color of the text using xml but I don't know how it is done in Java.
In xml is something like this:
android:textColor="@drawable/selected_color"
in JAVA ?
Assuming that by "drawable" you mean a selector with color items, you should refer to this question.
You won't be able to use the textcolor with image drawables, or selectors containing image drawables.