在bottomSheetDialogFragment中显示或关闭alertDialog时,可以通过以下方法避免闪烁/闪烁:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_bottom_sheet_dialog, container, false);
// 设置进入动画效果
Animation animation = AnimationUtils.loadAnimation(getContext(), R.anim.slide_up);
view.startAnimation(animation);
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// 显示alertDialog
showDialog();
}
}, 500); // 延迟500毫秒加载
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置透明主题
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Translucent_NoTitleBar);
}
这些方法可以帮助避免在bottomSheetDialogFragment中显示或关闭alertDialog时出现闪烁/闪烁的情况,提升用户体验。
参考链接:
领取专属 10元无门槛券
手把手带您无忧上云