gpt4 book ai didi

Android 为两个 Fragment 设置不同的主题,比如 Play Store

转载 作者:行者123 更新时间:2023-11-29 02:36:23 24 4
gpt4 key购买 nike

如何复制示例中交换主题更改的效果?

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

Play Store Effect

最佳答案

我认为那里没有应用动态主题。 viewpager 中的每个 fragment 都有其元素主题,具体取决于它们的主题。如果你想知道工具栏动画是如何完成的,我可以建议一种方法,它会给你相同的结果。

播放商店布局

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

过程将是:

  • 你开始Circular Reveal Animation在您的 OnPageChangeListener 的 onPageSelected 内的 revealContainer 上。
  • 在动画结束时设置 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();
}

关于Android 为两个 Fragment 设置不同的主题,比如 Play Store,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46769614/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com