Fragment 中监听返回按键

requireActivity()
    .onBackPressedDispatcher
    .addCallback(viewLifecycleOwner, object : OnBackPressedCallback(true) {
        override fun handleOnBackPressed() {
            if (isEnabled) {
                Log.d("test", "handleOnBackPressed: ")
            }
        }
    }
    )

你可能感兴趣的:(Fragment 中监听返回按键)