android - DialogFragment:创建片段时仅显示一次动画
问题描述
我的应用程序中有一个DialogFragment
在创建片段时使用动画来显示片段的地方。我就是这样做的
@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>
动画效果很好,但问题是每次恢复活动时都会发生这种情况。因此,如果片段正在显示并且我锁定屏幕然后解锁它以便暂停然后恢复活动,我会看到这个动画。我如何才能强制这种情况仅在创建片段时第一次发生并且不从那里显示它?提前致谢!
解决方案
在活动的 onCreate 而不是 onResume 中显示对话框?
推荐阅读
- c# - acumatica 中的重复动作
- c# - 如何确定 2 个多边形是否在 Gmap.net 中相交
- kotlin - Job 是从 CoroutineScope 启动的,SupervisorJob 也是 SupervisorJob 吗?
- functional-programming - 如何将数据传递到撰写管道的后期阶段
- python - 如何计算2个node2vec模型之间的距离
- python - 为 sympy.Derivative 创建自定义打印
- javascript - 删除一个 href 值,如果它存在使用 jquery
- linux - 使用 ifconfig 持久化进行更改
- html - 使用 translateY 滚动元素
- laravel - 如何在 laravel voyager 中迁移自定义 laravel 管理面板代码?