How to make the textview blinking

前端 未结 11 2078
谎友^
谎友^ 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:52

    Use XML Animations for this purpose :

    R.anim.blink

    
    
        
    
    

    Blink Activity: use it like this :-

    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) {
    
        }
    
    }
    

    Let me know if you have any queries..

提交回复
热议问题