Read More

BottomSheetDialogFragment with peekHeight equals to screen height

What is BottomSheetDialogFragment?

BottomSheetDialogFragment is a version of DialogFragment which is shown from the bottom instead of a floating dialog. Google introduced this in its Android version 23. It is used to show the additional content of the page and they have a nicer-looking entrance animation and since they are pinned to the bottom they may feel easier to use on larger devices. For detailed documentation, You can follow the official doc.

What is Peek Height?

Bottom Sheets have various states like STATE_COLLAPSED, STATE_EXPANDED, STATE_DRAGGING, STATE_SETTLING, and STATE_HIDDEN. Initially, the bottom sheet can cover a defined height of the screen and the user can drag is upwards to show it on full screen or the user can drag it downwards to dismiss it. When it is covering a definite height then it is in STATE_COLLAPSED state, when it is covering the full screen then it is in STATE_EXPANDED, and when it not shown on the screen then it is in STATE_HIDDEN. So, In case of STATE_COLLAPSED, the height for which the bottom sheet is showed is called the peek height which can be assigned as the below-given codes.

Hows the peeking bottom sheet looks like?

Here is an image of the bottom sheet peeking.

 

How to open the bottom sheet directly to full screen?

Recently, We got into a situation where we wanted to show a full-screen bottom layout directly (without the STATE_COLLAPSED). You can achieve this by programmatically setting two values.

but this will not be a smooth transition. You will be able to clearly notice a state change. To open the bottom sheet to full screen without a noticeable animation change, you need to add an onShowListener on the onCreate function of the BottomSheetDialogFragment which will be called as soon as the bottom sheet appears and set the peek height to device’s height.

Hope this has helped you in getting the idea of what exactly happening.

That’s all for this blog. Thank you very much. This is Vedesh Kumar signing off.

. . .

Comments (2)

Add Your Comment

  • kunj
    Nice Blog
  • css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close