Android为Play Store两个片段设置了不同的主题

Android为Play Store两个片段设置了不同的主题

问题描述:

如何从示例中看到我如何复制交换主题更改的效果?Android为Play Store两个片段设置了不同的主题

目前与setTheme()似乎不动态工作。

Play Store Effect

我觉得没有动态主题得到应用存在。 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