逐渐改变颜色

时间:2015-01-31 20:54:42

标签: android animation android-activity android-fragments android-animation

我借助此库制作了向上滑动面板。点击here现在我正在尝试逐渐更改顶部滑动面板的颜色,当用户打开面板或关闭时。我用过的下面的代码改变了flash中的颜色。 如何逐渐改变颜色?

@Override
public void onPanelLayout(View panel, SlidingUpPanelLayout.PanelState state) {
       LinearLayout titleBar = (LinearLayout) getView().findViewById(R.id.dragView);
       if(state == SlidingUpPanelLayout.PanelState.COLLAPSED){
                   titleBar.setBackgroundColor(Color.parseColor("#03A9F4"));
 }
 else if (state == SlidingUpPanelLayout.PanelState.ANCHORED || state == SlidingUpPanelLayout.PanelState.ANCHORED){
                    titleBar.setBackgroundColor(Color.parseColor("#ffff9431"));
 }
 }

感谢您的帮助和想法!

1 个答案:

答案 0 :(得分:3)

您可以使用TransitionDrawable

您的代码看起来像这样:

ColorDrawable transparentDrawable = new ColorDrawable();
transparentDrawable.setColor(0x00000000); //transparent white

ColorDrawable finalColorDrawable = 
finalColorDrawable.setColor(Color.parseColor("#ffff9431")); //your colour

Drawable[] layers = new Drawable[]{transparentDrawable, finalColorDrawable};
TransitionDrawable transitionDrawable = new TransitionDrawable(layers);

titleBar.setBackground(transitionDrawable);
transitionDrawable.startTransition(1000); //duration in milliseconds