如何
复制从示例中看到的交换主题更改的效果?
目前,setTheme() 似乎不能动态工作。
播放商店效果
我认为那里没有应用动态主题。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 -->
该过程将是:
- 您开始循环显示动画 揭示容器 在 onPageSelected 的 onPageChangeListener 中。
- 在动画结束时,您可以设置工具栏容器的背景。
- 隐藏显示容器
代码看起来像这样
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();
}