Created
May 15, 2019 15:30
-
-
Save esabook/d874d0a05d36c1fa23cdef54c5ad0dcb to your computer and use it in GitHub Desktop.
bootom sheet fragment BottomSheetBehavior
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
/** | |
* @param dialog | |
*/ | |
protected void setupDialogBehavior(Dialog dialog) { | |
dialog.setOnShowListener(dialog1 -> { | |
BottomSheetDialog d = (BottomSheetDialog) dialog; | |
View v = d.findViewById(android.support.design.R.id.design_bottom_sheet); | |
if (v != null) { | |
BottomSheetBehavior behavior = BottomSheetBehavior.from(v); | |
behavior.setSkipCollapsed(true); | |
behavior.setHideable(isCancelable()); | |
d.setOnKeyListener((di, keyCode, event) -> { | |
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { | |
setCancelable(true); | |
dialog.onBackPressed(); | |
return true; | |
} | |
return false; | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment