【发布时间】:2021-06-21 23:49:22
【问题描述】:
这是一个自定义的 DialogFragment。它在单个活动中运行良好,但是当应用程序在后台并返回时,它会再次启动它的弹出动画。那么如何预防这种情况呢?
public class GdtFeedbackFragment extends DialogFragment {
private static final String TAG = GdtFeedbackFragment.class.getSimpleName();
private Handler handler = new Handler(Looper.myLooper());
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = new Dialog(getActivity(), R.style.GdtTransparentFeedbackFragmentStyle);
if (dialog.getWindow() != null) {
Window window = dialog.getWindow();
window.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams params = window.getAttributes();
window.getAttributes().windowAnimations = R.style.DialogAnimationLandscape;
params.gravity = Gravity.CENTER;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
}
return dialog;
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
AdLog.i(TAG, "[onCreateView]");
return inflater.inflate(
R.layout.gdt_feedback_fragment_portrait,
container);
}
}
【问题讨论】:
-
问题可能不在于对话框类本身,而在于它的使用位置。您需要查看显示对话框的代码,并尝试找出在重新显示片段时可以调用它的情况下
标签: android animation dialogfragment