You don't really need these methods: initHeaderColor
& translateHeaderView
.
Define an ArgbEvaluator
as a class member:
ArgbEvaluator mArgbEvaluator;
// define start & end colors
int mStartColor, mEndColor;
// initialize start & end colors
Call ArgbEvaluator's evaluate
method with parameters (slideOffset, startColor, endColor)
, cast the return value to Integer
, and use it to set the background color of fmActionBar
:
void updateActionBarbgColor(float slideOffset) {
if (mArgbEvaluator == null)
mArgbEvaluator = new ArgbEvaluator();
int bgColor = (Integer) mArgbEvaluator.evaluate(slideOffset, mStartColor, mEndColor);
fmActionBar.setBackgroundColor(bgColor);
}
For reference, ArgbEvaluator#evaluate(...)
:
public Object evaluate(float fraction, Object startValue, Object endValue) {
int startInt = (Integer) startValue;
int startA = (startInt >> 24) & 0xff;
int startR = (startInt >> 16) & 0xff;
int startG = (startInt >> 8) & 0xff;
int startB = startInt & 0xff;
int endInt = (Integer) endValue;
int endA = (endInt >> 24) & 0xff;
int endR = (endInt >> 16) & 0xff;
int endG = (endInt >> 8) & 0xff;
int endB = endInt & 0xff;
return (int)((startA + (int)(fraction * (endA - startA))) << 24) |
(int)((startR + (int)(fraction * (endR - startR))) << 16) |
(int)((startG + (int)(fraction * (endG - startG))) << 8) |
(int)((startB + (int)(fraction * (endB - startB))));
}