-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
244893b
commit 4e2309b
Showing
4 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
.../main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUIAnimationUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore; | ||
|
||
import android.animation.ArgbEvaluator; | ||
import android.animation.ValueAnimator; | ||
import android.content.Context; | ||
import android.content.res.ColorStateList; | ||
|
||
import com.google.android.material.floatingactionbutton.FloatingActionButton; | ||
|
||
public class ChatUIAnimationUtils { | ||
// 定义静态全局变量来管理时间 | ||
public static final long DURATION_SHORT = 1000; // 1秒渐变 | ||
public static final double DURATION_LONG = 2022.1104; // 2秒左右渐变,星闪规范发布日 | ||
|
||
public static void animateBackgroundColorChange(Context context, FloatingActionButton button, int startColorRes, int endColorRes) { | ||
int startColor = context.getResources().getColor(startColorRes); | ||
int endColor = context.getResources().getColor(endColorRes); | ||
|
||
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), startColor, endColor); | ||
colorAnimation.setDuration((long) DURATION_LONG); // 动画持续时间,单位为毫秒 | ||
colorAnimation.setRepeatCount(ValueAnimator.INFINITE); // 无限循环 | ||
colorAnimation.setRepeatMode(ValueAnimator.REVERSE); // 反转颜色渐变 | ||
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | ||
@Override | ||
public void onAnimationUpdate(ValueAnimator animator) { | ||
button.setBackgroundTintList(ColorStateList.valueOf((int) animator.getAnimatedValue())); | ||
} | ||
}); | ||
colorAnimation.start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters