Skip to content

Instantly share code, notes, and snippets.

@diegohkd
Last active July 4, 2022 12:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save diegohkd/f14094879eaa58ba568dd14d319e86ce to your computer and use it in GitHub Desktop.
Save diegohkd/f14094879eaa58ba568dd14d319e86ce to your computer and use it in GitHub Desktop.
Show DialogFragment with full width set
fun DialogFragment.setupWidthToMatchParent() {
dialog?.window?.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
}
...
import androidx.fragment.app.DialogFragment
...
class FullWidthDialogFragment : DialogFragment() {
...
override fun getTheme(): Int = R.style.NoMarginsDialog
...
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupWidthToMatchParent()
}
...
}
<style name="NoMarginsDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">false</item>
</style>
@FarooqKhattak
Copy link

Very good work. But what if we want to give a little margin( e.g 5dp or 10dp) from the horizontals sides?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment