Android, How to use animation in order to show blinking?

时光总嘲笑我的痴心妄想 提交于 2020-01-15 06:25:30

问题


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?



来源:https://stackoverflow.com/questions/10326170/android-how-to-use-animation-in-order-to-show-blinking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!