Last active
September 22, 2020 15:44
-
-
Save Mojtaba-Shafaei/f66b8bcbc395fd07ac122b5bbfd11e8c to your computer and use it in GitHub Desktop.
Handle OnBackPressed in Fragments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getView().setFocusableInTouchMode(true); | |
getView().requestFocus(); | |
getView().setOnKeyListener((v, keyCode, event) -> { | |
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { | |
onBackPressed(); | |
return true; | |
} | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment