material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.35k stars 3.06k forks source link

[Dialogs] Full screen dialog #1862

Closed eric-labelle closed 2 years ago

eric-labelle commented 3 years ago

The full screen dialog described on material design website is not available and does not seem to be on the roadmap either.

Do you have any plans on adding this in a near future or is it expected for us to use the setView() with a custom DialogFragment?

dsn5ft commented 3 years ago

The animation there can be achieved with the new MaterialContainerTransform transition class (docs), using either a full-screen Fragment or Activity. That might be easier than trying to get a full-screen DialogFragment or Dialog working. Can you give that a try and let us know if you have any more specific questions about that potential setup?

VincentJoshuaET commented 3 years ago
open class FullScreenDialogFragment : DialogFragment() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NORMAL, R.style.FullScreenDialog)
    }

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val dialog = super.onCreateDialog(savedInstanceState)
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
        return dialog
    }

    override fun onStart() {
        super.onStart()
        dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
    }
}
<style name="FullScreenDialog" parent="Theme.MaterialComponents.DayNight.Dialog">
        <!-- Customize your theme here. -->
        <item name="android:windowBackground">@android:color/white</item>
        <item name="android:windowIsFloating">false</item>
</style>

I use this with Navigation Component so that the previous fragment does not get destroyed.