Color multi de Android en un TextView
Posible duplicado:
¿Es posible tener varios estilos dentro de un TextView?
Quiero que mi TextView muestre parte de su texto en rojo y otros en negro. Su contenido (el texto) se crea dinámicamente y no sé cuántas palabras serán de color rojo.
¿Hay alguna manera de hacer esto como en html-css?
Puede utilizar Spannable para lograr lo que desea.
String text = "This is <font color='red'>red</font>. This is <font color='blue'>blue</font>."; textView.setText(Html.fromHtml(text), TextView.BufferType.SPANNABLE);
Intenta de esta manera
TextView tv = (TextView)findViewById(R.id.tv); Spannable wordtoSpan = new SpannableString("I know just how to whisper, And I know just how to cry,I know just where to find the answers"); wordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 15, 30, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); wordtoSpan.setSpan(new ForegroundColorSpan(Color.RED), 5, 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); tv.setText(wordtoSpan);
Lo que básicamente quieres es SpannableString
Vea esto para el ejemplo completo: