如何在DialogFragment中接收onbackpressed?

时间:2017-08-01 13:15:38

标签: android android-fragments android-dialogfragment android-dialog dialogfragment

如何在DialogFragment中收到OnBackPressed事件?

我正在创建自定义DialogFragment,导致其调用onCreateView()而不是onCreateDialog

因此我无法设置OnDismissListenerOnCancelListener,因为mDialog为空。

我正在调用我的DialogFragment:

FragmentManager fragmentManager = ((AppCompatActivity) mContext).
                                getSupportFragmentManager();    
DialogFragmentCustom newFragment = DialogFragmentCustom.newInstance(...);
FragmentTransaction transaction = fragmentManager.beginTransaction();
                    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                    transaction.add(android.R.id.content, newFragment);
                    transaction.addToBackStack(null);
                    transaction.commit();

你知道如何解决我的问题吗?

0 个答案:

没有答案