在android中闪烁textview背景仅1秒钟一次

时间:2014-05-02 10:42:35

标签: android textview

我希望flash我的textview背景一段时间间隔(1000毫秒),这个是杀了我,因为我发现解决方案只是连续闪烁文本。但是我已经尝试过以下代码并且它仅适用于第一次,但是当我在10秒后刷新数据时,它会闪烁,只需更改颜色。

private void setBackgroundFlash(final TextView textView,
        final double oldValue, final double newValue) {

    if (oldValue > newValue)
        textView.setBackgroundColor(COLOR_FLASH_RED);
    else if (oldValue < newValue)
        textView.setBackgroundColor(COLOR_FLASH_GREEN);
    else if (oldValue == newValue)
        textView.setBackgroundResource(Color.TRANSPARENT);

    CountDownTimer timerForTextFlash = new CountDownTimer(1000, 100) {

        @Override
        public void onTick(long millisUntilFinished) {

        }

        @Override
        public void onFinish() {
            textView.setBackgroundResource(Color.TRANSPARENT);
        }

    };
    timerForTextFlash.start();
}

1 个答案:

答案 0 :(得分:2)

试试这个

yourView.startAnimation(getBlinkAnimation());

public Animation getBlinkAnimation(){
        Animation animation = new AlphaAnimation(1, 0);         // Change alpha from fully visible to invisible
        animation.setDuration(300);                             // duration - half a second
        animation.setInterpolator(new LinearInterpolator());    // do not alter animation rate
        animation.setRepeatCount(1);                            // Repeat animation infinitely
        animation.setRepeatMode(Animation.REVERSE);             // Reverse animation at the end so the button will fade back in

        return animation;
    }