0
色の青で始まるツールバーに...私のコラプスツールバーの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));
}
});
してください、私を助けて...
EDIT#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の依存関係も更新します。私は自分の答えを更新しました。 –