Last active
July 4, 2022 12:21
-
-
Save diegohkd/f14094879eaa58ba568dd14d319e86ce to your computer and use it in GitHub Desktop.
Show DialogFragment with full width set
This file contains 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
fun DialogFragment.setupWidthToMatchParent() { | |
dialog?.window?.setLayout( | |
ViewGroup.LayoutParams.MATCH_PARENT, | |
ViewGroup.LayoutParams.WRAP_CONTENT | |
) | |
} |
This file contains 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 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() | |
} | |
... | |
} |
This file contains 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
<style name="NoMarginsDialog" parent="Theme.AppCompat.Light.Dialog"> | |
<item name="android:windowBackground">@android:color/transparent</item> | |
<item name="android:windowIsFloating">false</item> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very good work. But what if we want to give a little margin( e.g 5dp or 10dp) from the horizontals sides?