Cómo hacer que la vista de texto parpadee

Chicos tengo un textview que necesito que parpadee por favor me ayude con él.

<TextView android:id="@+id/usage" android:layout_marginTop="220dip" android:layout_marginLeft="45dip" android:layout_marginRight="15dip" android:typeface="serif" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Google " android:textColor="#030900"/> 

Quiero que el texto de google esté parpadeando

Es una respuesta obsoleta a Android antes de la versión 3.0 , por favor usa la respuesta de SolArabehety o mira este hilo.

Respuesta Original

 package teste.blink; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.widget.TextView; public class TesteBlinkActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); blink(); } private void blink(){ final Handler handler = new Handler(); new Thread(new Runnable() { @Override public void run() { int timeToBlink = 1000; //in milissegunds try{Thread.sleep(timeToBlink);}catch (Exception e) {} handler.post(new Runnable() { @Override public void run() { TextView txt = (TextView) findViewById(R.id.usage); if(txt.getVisibility() == View.VISIBLE){ txt.setVisibility(View.INVISIBLE); }else{ txt.setVisibility(View.VISIBLE); } blink(); } }); } }).start(); } 

 <TextView android:id="@+id/usage" android:layout_marginTop="220dip" android:layout_marginLeft="45dip" android:layout_marginRight="15dip" android:typeface="serif" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Google " android:textColor="#030900"/> 

Puede utilizar esto:

 TextView myText = (TextView) findViewById(R.id.myText ); Animation anim = new AlphaAnimation(0.0f, 1.0f); anim.setDuration(50); //You can manage the blinking time with this parameter anim.setStartOffset(20); anim.setRepeatMode(Animation.REVERSE); anim.setRepeatCount(Animation.INFINITE); myText.startAnimation(anim); 

Es la misma respuesta que he dado en este mensaje Texto intermitente en la vista de Android

¡Espero que esto ayude!

Utilice animaciones XML para este propósito:

R.anim.blink

 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:interpolator="@android:anim/accelerate_interpolator" android:duration="600" android:repeatMode="reverse" android:repeatCount="infinite"/> </set> 

Actividad Blink: úsalo así: –

 public class BlinkActivity extends Activity implements AnimationListener { TextView txtMessage; Button btnStart; // Animation Animation animBlink; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_blink); txtMessage = (TextView) findViewById(R.id.txtMessage); btnStart = (Button) findViewById(R.id.btnStart); // load the animation animBlink = AnimationUtils.loadAnimation(this, R.anim.blink); // set animation listener animBlink.setAnimationListener(this); // button click event btnStart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { txtMessage.setVisibility(View.VISIBLE); // start the animation txtMessage.startAnimation(animBlink); } }); } @Override public void onAnimationEnd(Animation animation) { // Take any action after completing the animation // check for blink animation if (animation == animBlink) { } } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { } } 

Déjame saber si tienes alguna pregunta ..

Cree una AlphaAnimation y aplíquela a la vista de texto en la actividad donde ha configurado la vista de texto. El parpadeo se lograría repitiendo una animación de 1,0 alfa a 0,0 alfa a 1,0 alfa.


Editar : Google provideth .

No es necesario establecer para esto. Sólo alfa:

Anim / flash_leave_now.xml

  <?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="900" android:fromAlpha="1.0" android:repeatCount="infinite" android:repeatMode="reverse" android:toAlpha="0.2"/> 

Y en código:

 mTextView.setAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.flash_leave_now)); 

Usted puede hacer una animación o tal vez por qué no lo hace View.VISIBLE y View.INVISIBLE con un temporizador? Creo que la mejor manera es la animación con alpha de hecho 🙂

Aquí está mi implementación de ayuda con una animación alfa:

  public void blinkText(final TextView text_to_animate, int durationMillis) { final AlphaAnimation fade_out = new AlphaAnimation(1.0f, 0.0f); //ScaleAnimation scale_it = new ScaleAnimation(1.0f, 1.25f, 1.0f, 1.25f); fade_out.setDuration(durationMillis); final AlphaAnimation fade_in = new AlphaAnimation(0.0f, 1.0f); //ScaleAnimation scale_it = new ScaleAnimation(1.0f, 1.25f, 1.0f, 1.25f); fade_in.setDuration(durationMillis); fade_out.setAnimationListener(new AnimationListener() { public void onAnimationEnd(Animation arg0) { // TODO Auto-generated method stub if (recording == true) text_to_animate.startAnimation(fade_in); } public void onAnimationRepeat(Animation arg0) { // TODO Auto-generated method stub } public void onAnimationStart(Animation arg0) { // TODO Auto-generated method stub } }); fade_in.setAnimationListener(new AnimationListener() { public void onAnimationEnd(Animation arg0) { // TODO Auto-generated method stub if (recording == true) text_to_animate.startAnimation(fade_out); } public void onAnimationRepeat(Animation arg0) { // TODO Auto-generated method stub } public void onAnimationStart(Animation arg0) { // TODO Auto-generated method stub } }); text_to_animate.startAnimation(fade_out); } 
  • Textview actuar como un terminal
  • Android TextView ¿Qué hace eleganteTextHeight? (API 21)
  • Abrir vínculos de TextView en otra actividad, no en el navegador predeterminado
  • Android SpannableString establecer fondo detrás de parte del texto
  • TextView rellenado dinámicamente cortando la última línea de texto
  • Android: ¿Cómo puedo actualizar mi textView en un fragmento
  • Autosizing de TextView no funciona (Android O)
  • ¿Cuáles son la semántica de cada constante de InputType?
  • Cómo convertir SpannedString a Spannable
  • Img src atributo de json valor que muestra pequeña caja de color azul en Android TextView
  • Eliminar el fondo de una vista de texto
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.