Skip to main content

Blinking TextView - Two Methods

METHOD 1
private void blink(){
            final Handler handler = new Handler();
            new Thread(new Runnable() {
                public void run() {
                int timeToBlink = 600;    //in milissegunds
                try
                {
                    Thread.sleep(timeToBlink);
                }catch (Exception e)
                {
                   
                }handler.post(new Runnable()
                  {
                   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();
            }
METHOD 2
   TextView myText = (TextView) findViewById(R.id.usage );
   Animation anim = new AlphaAnimation(0.0f, 1.0f);
   anim.setDuration(50);
   //You can manage the time of the blink with this parameter
   anim.setStartOffset(20);
   anim.setRepeatMode(Animation.REVERSE);
   anim.setRepeatCount(Animation.INFINITE);
   myText.startAnimation(anim); 

Comments