2017-10-16 85 views

回答

0

我覺得沒有動態主題得到應用存在。 viewpager中的每個片段都有其主題,因爲它們的主題依賴於它們的主題。如果你想知道工具欄動畫是如何完成的,我可以建議一種方法,它會給你相同的結果。

Play商店佈局

<Toolbar> 
    <FrameLayout> 
     <RelativeLayout id="toolbarContainer"> 
     </RelativeLayout> 
     <RelativeLayout id="revealContainer"> 
     </RelativeLayout> 
     <TabLayout></TabLayout> 
    </FrameLayout> 
</Toolbar> 
<StoreView></StoreView><!-- This is where you see viewpager fragments --> 

的過程將是:

  • revealContainer裏面你OnPageChangeListener的使用onPageSelected開始Circular Reveal Animation
  • 在動畫結束時,您設置的背景爲toolbarContainer
  • 隱藏revealContainer

的代碼會是這個樣子

viewPager.setOnPageChangeListener(new OnPageChangeListener() { 
public void onPageScrollStateChanged(int state) {} 
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} 
public void onPageSelected(int position) { 
// new position of page 
showRevealEffectForPage(position); 
} 
}); 

private void showRevealEffectForPage(int page) { 
int color; 
switch(page) { 
case 0: 
color = Color.parseColor("#fff"); //white 
break; 
default: 
color = Color.parseColor("#000"); //black 
break; 
} 

//set color before animation starts 
revealContainer.setBackgroundColor(color); 

int x = revealContainer.getRight(); 
int y = revealContainer.getBottom(); 

int startRadius = 0; 
int endRadius = (int) Math.hypot(toolbarContainer.getWidth(), toolbarContainer.getHeight()); 

Animator anim = ViewAnimationUtils.createCircularReveal(revealContainer, x, y, startRadius, endRadius); 

layoutButtons.setVisibility(View.VISIBLE); 
// you can set animation listener here to check for when the animation ends by 

anim.setAnimationListener(new Animation.AnimationListener() { 
    @Override 
    public void onAnimationStart(Animation animation) { 

    } 

    @Override 
    public void onAnimationEnd(Animation animation) { 
//set the color of toolbarContainer 
toolbarContainer.setBackgroundColor(color); 
revealContainer.setVisibility(View.INVISIBLE); 
    } 

    @Override 
    public void onAnimationRepeat(Animation animation) { 

    } 
}); 

anim.start(); 
} 
+0

謝謝您的回答@codekidX – antia

+0

我不認爲它只是主題化的元素。如果是這樣,主要顏色不會改變,但當您打開「最近」屏幕時,Playstore的標題欄顏色與您選項卡的顏色相同,這隻能表示主要顏色真的在變化。我不知道它是如何做的,但我也在尋找答案 –

+0

@LuccasClezar我認爲setTheme(R.style.YourTheme); _ [在其中colorPrimary不同] _被調用。這可能是在選項卡更改後設置的。 – codekidX

相關問題