Skip to content

Latest commit

 

History

History
113 lines (72 loc) · 2.22 KB

README.md

File metadata and controls

113 lines (72 loc) · 2.22 KB

AppCompat-DialogFragment

Introduction

This is a adapter for DialogFragment!

Useage

  1. Enable databinding

    android {
        ...
            
        dataBinding {
            enabled = true
        }
    }
  2. 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!

  3. Use AppCompatDialogFragmentAdapter

    Define your dialog fragment with you needed bindLayout and initView

    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")
  4. Use AppCompatBottomSheetDialogFragment

    Define your dialog fragment with you needed bindLayout and initView

    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")

More

  • see source code!