0
进入我的工具栏,以蓝色开始......当我滚动我的colapsing工具栏的10%时,它会保持更黑,更多20%黑... 100%全回...垂直滚动的工具栏渐变颜色
任何人都有任何想法我该怎么做?
我使用此代码,但只从蓝到黑跳...
appBar.addOnOffsetChangedListener(new AppBarStateChangeListener() {
@Override
public void onStateChanged(AppBarLayout appBarLayout, State state) {
if (state == State.COLLAPSED) {
btCollapseCards.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_keyboard_arrow_down_white_24dp));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
toolbarLayout.setBackgroundDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.background_gradient_black));
llCardTitle.setBackgroundDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.background_gradient_black));
} else {
toolbarLayout.setBackground(ContextCompat.getDrawable(getActivity(), R.drawable.background_gradient_black));
llCardTitle.setBackground(ContextCompat.getDrawable(getActivity(), R.drawable.background_gradient_black));
}
} else if (state == State.EXPANDED) {
btCollapseCards.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_keyboard_arrow_up_white_24dp));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
toolbarLayout.setBackgroundDrawable(ContextCompat.getDrawable(getActivity(), R.color.colorPrimary));
llCardTitle.setBackgroundDrawable(ContextCompat.getDrawable(getActivity(), R.color.colorPrimary));
} else {
toolbarLayout.setBackground(ContextCompat.getDrawable(getActivity(), R.color.colorPrimary));
llCardTitle.setBackground(ContextCompat.getDrawable(getActivity(), R.color.colorPrimary));
}
}
int toolBarHeight = toolbar.getMeasuredHeight();
int appBarHeight = appBarLayout.getMeasuredHeight();
Float f = ((((float) appBarHeight - toolBarHeight) + verticalOffset)/((float) appBarHeight - toolBarHeight)) * 255;
viewBackground.getBackground().setAlpha(255 - Math.round(f));
}
});
请帮我...
编辑#01
插入码,当我向上滚动时发挥了我想要的效果......但是当我向下滚动时,不会得到相同的效果。
int toolBarHeight = toolbar.getMeasuredHeight();
int appBarHeight = appBarLayout.getMeasuredHeight();
Float f = ((((float) appBarHeight - toolBarHeight) + verticalOffset)/((float) appBarHeight - toolBarHeight)) * 255;
viewBackground.getBackground().setAlpha(255 - Math.round(f));
我做了我的问题有些变化......我试图用你的dynamicToolbarColor,但没有发现导入调色板...你能帮我吗? –
也更新你的build.gradle依赖关系..我已经更新了我的答案。 –