Last active
January 18, 2024 16:02
-
-
Save vahid-m/6ce58713a7fe1b0cea04673ed0b89d49 to your computer and use it in GitHub Desktop.
DialogFragment with MaterialAlertDialog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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