Android DialogFragment Fullscreen Like Activity

We can use DialogFragment to show a fullscreen overlay (like loading an Activity, but with Fragment).

Why not use a Fragment instead of DialogFragment. With Fragment, you would need to prepare a fullscreen layout and load/replace the Fragment into the layout. With DialogFragment, there is no need of such layout.

The following code and layout will create a layout with black overlay which filled 90% of the screen.

class GiftDialog : DialogFragment() {    companion object {        private const val FRAGMENT_TAG = "gift_dialog"        fun newInstance() = GiftDialog()        fun show(fragmentManager: FragmentManager): GiftDialog {            val dialog = newInstance()            // dialog.isCancelable = false  , FRAGMENT_TAG)            return dialog        }    }    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {        // return super.onCreateView(inflater, container, savedInstanceState)        return activity!!.layoutInflater.inflate(, container)    }}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""


            android:text="Hello World" />


NOTE: If you use LinearLayout as root layout, the dialog size will shrink to minimum. Refer Android DialogFragment Match Parent Width and Height.

To match 100% with and height (like an Activity) without black overlay background.

class GiftDialog : DialogFragment() {    ...    override fun onCreate(savedInstanceState: Bundle?) {        super.onCreate(savedInstanceState)        setStyle(STYLE_NO_TITLE,        // this will make it fullscreen without top status bar        // setStyle(STYLE_NO_TITLE,    }}

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.