Reputation: 153
How can i open bottom dialog sheet on full screen mode.But whenever I click on that it just open half screen view and than i m scroll to full screen .But One more thing this is in Adapter class
var flashAlertPopUp = FareDetailBottomSheet(data.fare_details)
flashAlertPopUp.show(childFragmentManager, "")
Upvotes: 0
Views: 335
Reputation: 22832
Override setupDialog()
in your child BottomSheetDialogFragment
to set it expanded with the height of the screen size, like following:
override fun setupDialog(dialog: Dialog, style: Int) {
super.setupDialog(dialog, style)
val parentView = rootView.parent as View
val params = parentView.layoutParams as CoordinatorLayout.LayoutParams
val behavior = params.behavior
if (behavior != null && behavior is BottomSheetBehavior<*>) {
behavior.state = BottomSheetBehavior.STATE_EXPANDED
behavior.peekHeight = requireContext().screenSize.y
}
}
val Context.screenSize: Point
get() = Point().also {
(getSystemService(Context.WINDOW_SERVICE) as? WindowManager)?.defaultDisplay?.getSize(it)
}
In Java code:
public class FareDetailBottomSheet extends BottomSheetDialogFragment {
private View rootView;
@SuppressLint("RestrictedApi")
@Override
public void setupDialog(@NonNull Dialog dialog, int style) {
super.setupDialog(dialog, style);
// layoutResId: your layout resource id
rootView = View.inflate(requireContext(), layoutResId, null);
dialog.setContentView(rootView);
onInitViews();
View parentView = (View) rootView.getParent();
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) parentView.getLayoutParams();
CoordinatorLayout.Behavior behavior = params.getBehavior();
if (behavior instanceof BottomSheetBehavior) {
((BottomSheetBehavior) behavior).setState(BottomSheetBehavior.STATE_EXPANDED);
((BottomSheetBehavior) behavior).setPeekHeight(getScreenSize().y);
}
}
private void onInitViews() {
// do your initialization here...
// for example:
// TextView textView = rootView.findViewById(R.id.textView);
}
private Point getScreenSize() {
Point point = new Point();
WindowManager wm = (WindowManager) requireContext().getSystemService(Context.WINDOW_SERVICE);
if (wm.getDefaultDisplay() != null) {
wm.getDefaultDisplay().getSize(point);
}
return point;
}
}
Upvotes: 1