¿Hay alguna manera de animar un cambio de color de texto (de cualquier color a blanco)?Animación de color de texto
La única variante me ocurrió, está colocando dos textviews (con el mismo texto) en un lugar, y la decoloración el de arriba, por lo que el inferior (que tiene un color blanco) se hará visible.
P.S. Eliminé la variante de los 2 TextViews porque parecía raro (los bordes no eran uniformes y, como tengo muchos de esos elementos en la pantalla, realmente estaba retrasando el desplazamiento). Lo que hice fue un hack loco que hace la animación con el uso de un Thread y setTextColor (que también fuerza el redibujado de una vista de texto).
Como necesitaba solo 2 cambios de color (de rojo a blanco, y de verde a blanco) codifiqué los valores y todos los colores de transición entre ellos. Así que aquí es cómo se ve:
public class BlinkingTextView extends TextView {
public BlinkingTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void animateBlink(final boolean red) {
if (animator != null) {
animator.drop();
}
animator = new Animator(this, red);
animator.start();
}
public void clearBlinkAnimation() {
if (animator != null) {
animator.drop();
}
}
private Animator animator;
private final static class Animator extends Thread {
public Animator(final TextView textView, final boolean red) {
this.textView = textView;
if (red) {
SET_TO_USE = RED;
} else {
SET_TO_USE = GREEN;
}
}
private TextView textView;
private final int[] SET_TO_USE;
private final static int[] RED = {
-2142396,
-2008754,
-1874854,
-1740697,
-1540490,
-1405563,
-1205099,
-1004634,
-804170,
-669243,
-469036,
-334879,
-200979,
-67337,
-1
};
private final static int[] GREEN = {
-6959821,
-6565826,
-6106293,
-5646758,
-5055894,
-4530309,
-3939444,
-3283042,
-2692177,
-2166592,
-1575728,
-1116193,
-656660,
-262665,
-1
};
private boolean stop;
@Override
public void run() {
int i = 0;
while (i < 15) {
if (stop) break;
final int color = SET_TO_USE[i];
if (stop) break;
textView.post(new Runnable() {
@Override
public void run() {
if (!stop) {
textView.setTextColor(color);
}
}
});
if (stop) break;
i++;
if (stop) break;
try {
Thread.sleep(66);
} catch (InterruptedException e) {}
if (stop) break;
}
}
public void drop() {
stop = true;
}
}
}
Gracias . De hecho, no he implementado el método del que estaba hablando (solo lo pensé). Muchas gracias, voy a probar su método ahora :) –