Skip to content

Instantly share code, notes, and snippets.

@vxhviet
Created May 20, 2020 03:31
Show Gist options
  • Save vxhviet/a8b1592a1af82146f4aad99ffe4d9261 to your computer and use it in GitHub Desktop.
Save vxhviet/a8b1592a1af82146f4aad99ffe4d9261 to your computer and use it in GitHub Desktop.

Android - Remove default Background and border for Dialog Fragment and make it match parent

SOURCE, SOURCE, SOURCE

abstract class BaseDialogFragment : DialogFragment() {
    override fun onStart() {
        super.onStart()
        // match_parent doesn't work in xml thus we have to manually set it here
        // https://stackoverflow.com/a/12923805/1602807
        // https://stackoverflow.com/a/28596836/1602807
        dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        // remove default background and border, see https://stackoverflow.com/a/28528209/1602807
        dialog?.requestWindowFeature(Window.FEATURE_NO_TITLE)
        dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        setStyle(STYLE_NO_FRAME, android.R.style.Theme)
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment