This is a adapter for DialogFragment!
-
Enable databinding
android { ... dataBinding { enabled = true } }
-
Config gradle
Add it in your root build.gradle at the end of repositories:
repositories { jcenter() }
Add dependencies
implementation 'com.murphy.appcompat:dialogfragment:1.0.5'
library module is full kotlin language, so it need add material dependencies when used that because if dont add this you can seeing the Kotlin issue KT-31052
implementation 'com.google.android.material:material:1.2.0'
if you can fix it, commit issue!
-
Use AppCompatDialogFragmentAdapter
Define your dialog fragment with you needed
bindLayout
andinitView
class NormalDialogFragment() : AppCompatDialogFragmentAdapter<DialogFragmentNormalBinding> { override fun initView(dataBinding: DialogFragmentNormalBinding) { dataBinding.button.setOnClickListener { dismiss() } } override fun bindLayout(): Int { return R.layout.dialog_fragment_normal } }
Use
val normalDialogFragment = NormalDialogFragment() normalDialogFragment.isCancelable = false normalDialogFragment.show(supportFragmentManager, "normal")
-
Use AppCompatBottomSheetDialogFragment
Define your dialog fragment with you needed
bindLayout
andinitView
class NormalBottomSheetFragment : AppCompatBottomSheetDialogFragment<DialogFragmentBottomBinding>() { override fun initView(dataBinding: DialogFragmentBottomBinding) { dataBinding.button.setOnClickListener { dismiss() } } override fun bindLayout(): Int { return R.layout.dialog_fragment_bottom } }
Use
val normalBottomSheetFragment = NormalBottomSheetFragment() normalBottomSheetFragment.show(supportFragmentManager, "bottom")
- see source code!