gpt4 book ai didi

android - 对话框 fragment : Show animation only once when fragment is created

转载 作者:行者123 更新时间:2023-12-05 00:06:05 25 4
gpt4 key购买 nike

我的应用程序中有一个 DialogFragment,我在其中使用动画在创建 fragment 时显示它。我是这样做的,

    @Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
// Set a theme on the dialog builder constructor!
AlertDialog.Builder builder =
new AlertDialog.Builder( getActivity(), R.style.MyCustomTheme );

builder
.setTitle( "Your title" )
.setMessage( "Your message" )
.setPositiveButton( "OK" , new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
dismiss();
}
});
return builder.create();
}
}

和主题

<style name="MyCustomTheme" parent="@android:style/Theme.Panel">
<item name="android:windowAnimationStyle">@style/MyAnimation.Window</item>
</style>

<style name="MyAnimation.Window" parent="@android:style/Animation.Activity">
<item name="android:windowEnterAnimation">@anim/anim_in</item>
<item name="android:windowExitAnimation">@anim/anim_out</item>
</style>

动画效果很好,但问题是每次恢复 Activity 时都会发生这种情况。因此,如果 fragment 正在显示并且我锁定屏幕然后解锁它以便 Activity 暂停然后恢复我看到这个动画。如何在创建 fragment 时强制仅在第一次发生并且不从那里显示它?提前致谢!

最佳答案

在 Activity 的 onCreate 而不是 onResume 中显示对话框?

关于android - 对话框 fragment : Show animation only once when fragment is created,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55728840/

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