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依賴關係..我已經更新了我的答案。 –