How to make the textview blinking

前端 未结 11 2064
谎友^
谎友^ 2020-12-02 09:14

Guys i have a textview which i need it to be blinking please help me with it.



        
11条回答
  •  独厮守ぢ
    2020-12-02 09:39

    Courtesy to the top answer, this is what i did:

     textBlink = new TimerTask() {
            int countdown = 10;
    
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (countdown <= 0) {
                            timer.cancel();
                            textview.setVisibility(View.GONE);
                        } else {
                                textview.setVisibility(textview.getVisibility() == View.VISIBLE?View.GONE:View.VISIBLE);
                            countdown--;
                        }
                    }
                });
            }
        };
    

    then somewhere on the code:

      timer = new Timer();
      timer.scheduleAtFixedRate(textBlink,0,500);
    

    This will do a blink effect for 5 seconds. Recommended for if you don't want the fadeIn-fadeOut effect.

提交回复
热议问题