Skip to content

Instantly share code, notes, and snippets.

@vahid-m
Last active January 18, 2024 16:02
Show Gist options
  • Save vahid-m/6ce58713a7fe1b0cea04673ed0b89d49 to your computer and use it in GitHub Desktop.
Save vahid-m/6ce58713a7fe1b0cea04673ed0b89d49 to your computer and use it in GitHub Desktop.
DialogFragment with MaterialAlertDialog
import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.fragment.app.DialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
open class MaterialDialogFragment : DialogFragment() {
private var dialogView: View? = null
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return MaterialAlertDialogBuilder(requireContext(), theme).apply {
dialogView = onCreateView(LayoutInflater.from(requireContext()), null, savedInstanceState)
dialogView?.let { onViewCreated(it, savedInstanceState) }
setView(dialogView)
}.create()
}
override fun getView(): View? {
return dialogView
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment