DialogFragment:创建片段时仅显示一次动画

问题描述 投票:0回答:1

我在我的应用程序中有一个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>    

动画工作正常,但问题是每次恢复活动时都会发生这种情况。因此,如果片段显示,我锁定屏幕,然后解锁它,以便活动暂停,然后恢复,我看到这个动画。如何才能在创建片段时第一次强制执行此操作并且不显示片段?提前致谢!

android android-fragments android-dialogfragment
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.