Skip to content

Instantly share code, notes, and snippets.

@arnold-wafula
Created February 3, 2023 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnold-wafula/a2ad8233a69e4475b0b4a3a500ae2bfa to your computer and use it in GitHub Desktop.
Save arnold-wafula/a2ad8233a69e4475b0b4a3a500ae2bfa to your computer and use it in GitHub Desktop.
package com.lemonboy.modalbottomsheet.dialog
import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.lemonboy.modalbottomsheet.databinding.ItemBottomsheetBinding
class ModalBottomSheetDialog : BottomSheetDialogFragment() {
private lateinit var binding : ItemBottomsheetBinding
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = ItemBottomsheetBinding.inflate(inflater, container, false)
return binding.root
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
// used to show the bottom sheet dialog
dialog?.setOnShowListener { it ->
val d = it as BottomSheetDialog
val bottomSheet = d.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)
bottomSheet?.let {
val behavior = BottomSheetBehavior.from(it)
behavior.state = BottomSheetBehavior.STATE_EXPANDED
}
}
return super.onCreateDialog(savedInstanceState)
}
companion object {
const val TAG = "ModalBottomSheetDialog"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment