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 like this:
res/color/your_colors.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#ffffffff"/>
<item android:color="#ff1c5fab"/>
</selector>
You can use this code: mText.setTextColor(getResources().getColorStateList(R.color.your_colors));