0

我制作的在该库的帮助下向上滑动面板。点击here现在我试图在用户打开面板或关闭时逐渐改变顶部滑动面板的颜色。下面的代码,我用下面的代码改变闪光灯的颜色。 如何逐渐改变颜色?逐渐改变颜色

@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")); 
} 
} 

感谢您的任何帮助和想法!

回答

2

你可以使用一个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