慕村9548890
onBackPressed 回调由您的父活动处理。因此您可以覆盖父活动的回调XyzActivity.java:@Overridepublic void onBackPressed() { handleBackPress();}public void handleBackPress() { Fragment visibleFragment = getSupportFragmentManager().findFragmentById(R.id.fragmentFrameLayout); if (visibleFragment == null) { return; }else if (visibleFragment instanceof PreviewFragment) { CommonFunctions.showDialogActionable(this, "Confirm", "Are you sure you want to exit?", "Yes", (dialogInterface, i) -> { finish(); }, "No", null, "", null, true); return; }else finish(); super.onBackPressed();}