Skip to content

Android Navigation Bottom Sheet — Complete Guide

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Android Navigation Bottom Sheet. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

Your bottom sheet doesn't expand to full height, the navigation inside the sheet doesn't work, or dragging dismisses the sheet accidentally.

Wrong Approach ❌

// Bare BottomSheetDialogFragment without proper container
class MyBottomSheet : BottomSheetDialogFragment() {
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_sheet, container, false)
    }
}
<!-- No CoordinatorLayout — sheet can't drag properly -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView android:text="Content" />
</FrameLayout>

Output: Bottom sheet doesn't respond to drag gestures. Peek height doesn't work.

Right Approach ✅

class MyBottomSheet : BottomSheetDialogFragment() {
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
        return inflater.inflate(R.layout.fragment_sheet, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        // Set peek height programmatically
        dialog?.let { dialog ->
            val sheet = dialog.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)
            sheet?.layoutParams?.height = ViewGroup.LayoutParams.MATCH_PARENT
        }

        // Prevent accidental dismiss on drag down
        isCancelable = true
        setStyle(STYLE_NORMAL, R.style.ThemeOverlay_Material3_BottomSheetDialog)
    }

    // Navigation inside bottom sheet
    private fun navigateToSubScreen() {
        val navController = findNavController()
        // Use a nested NavHostFragment inside the sheet if needed
    }
}

// With ViewPager2 inside bottom sheet
class TabbedBottomSheet : BottomSheetDialogFragment() {
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val adapter = ViewPagerAdapter(this)
        view.findViewById<ViewPager2>(R.id.viewPager).adapter = adapter
    }
}

Output: Bottom sheet expands to full height, handles navigation correctly.

Prevention

  • Use BottomSheetDialogFragment for content with drag-to-dismiss.
  • Set MATCH_PARENT on the bottom sheet container for full height.
  • Use NestedScrollView inside bottom sheet for scrollable content.
  • For navigation, use a nested NavHostFragment inside the sheet.

Common Mistakes with navigation bottom sheet

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. Non-exhaustive pattern matches that compile with warnings then crash at runtime

These mistakes appear frequently in real-world Android code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is peek height in a bottom sheet?

Peek height is the visible portion when the sheet is collapsed. Set it with app:behavior_peekHeight="120dp" in XML or programmatically via BottomSheetBehavior.

### How do I prevent the bottom sheet from being dismissed on drag?

Set isCancelable = false or set the BottomSheetBehavior state to STATE_EXPANDED with skipCollapsed = true.

### Can I use Navigation Component inside a bottom sheet?

Yes. Add a NavHostFragment inside the bottom sheet layout and navigate within it. Each bottom sheet can have its own nav graph.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro