How to disable back button pressed in android fragment class

后端 未结 9 1140
别跟我提以往
别跟我提以往 2020-12-11 14:39

I want to disable the back button in a fragment class. onBackPressed() doesn\'t seem to work in this fragment. How could I disable the back button?

This

9条回答
  •  时光说笑
    2020-12-11 14:58

    I know it's too late, In fragment onCreate

    val callback = requireActivity().onBackPressedDispatcher.addCallback(this) {
    Log.d("tag","back button pressed")    // Handle the back button event
    }
    
    callback.isEnabled
    

提交回复
热议问题