Android, How to use animation in order to show bli

2019-07-17 19:52发布

问题:

In my application, I have recording button. I want when user clicks on it each one second i change the background in order to simulate blinking. I created a handler and set it to 1 second therefore each one second this handler runs. Here i change the background. this my code:

mUpdateUITimerTask = new Runnable() {
            public void run() {

                // Simulating blinking for capture button
                if(bolToggle) {
                    bolToggle = false;
                    captureButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_record_blink));
                } else {
                    bolToggle = true;
                    captureButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_record));
                }

                mHandler.postDelayed(mUpdateUITimerTask, 1000);
            }
        };

When I run the app i see the changes but its not clear. buttons are like this:

When i run the application, red image is showing ok but for white image, it shows red image with a little white halo around it. I tried to put captureButton.setBackgroundColor(Color.TRANSPARENT); before setting background but result was same.

any suggestion would be appreciated. Thank you.

回答1:

Found the answer you need: https://stackoverflow.com/a/4852468/1352556

Basically you want an alpha animation. I believe this will make the entire button flash however, do you only want the red dot flashing?