androidcolorsspannable

how to set font color code in spannable String?


I want to set the color code in a spannable string.

 SpannableString str= new SpannableString("Your new message ");
        str.setSpan(new ForegroundColorSpan("#00ff00", 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

I have tried the above code but it is not working.


Solution

  • Here color is an integer you should use :

    Color.parseColor("#ff00ff00")