How to use data-binding in Dialog?

前端 未结 8 1926
傲寒
傲寒 2021-01-30 12:29

I am having trouble in implementing databinding in a Dialog. Is it possible?

Below is my xml.



    

        
8条回答
  •  逝去的感伤
    2021-01-30 13:02

    If your dialog shrink, Try this

    I tried @Dullahan's answer, however the dialog seemed to shrink strangely. So I tried another ways, finally found solution.

    
    
        
    
            
    
        
    
    
    class CustomDialog(context: Context) : Dialog(context) {
        private lateinit var binding: CustomDialogBinding
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.custom_dialog)
            binding = CustomDialogBinding.bind(findViewById(R.id.root))
        }
    }
    

提交回复
热议问题