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