18034727885
2026-04-14 370014cbb9ec1ef64e7e42bb4f9a12671461d8e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.xw.common.base
 
import android.app.Dialog
import android.content.Context
import android.view.LayoutInflater
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
 
abstract class BaseDialog<T : ViewDataBinding>(mContext: Context, themeResId: Int = 0) : Dialog(mContext, themeResId) {
    var binding: T? = null
 
    abstract fun getLayoutId(): Int
    abstract fun initData()
 
    init {
        if (getLayoutId() > 0) {
            val view = LayoutInflater.from(mContext).inflate(getLayoutId(), null)
            with(view) {
                setContentView(this)
                binding = DataBindingUtil.bind(this)
                initData()
            }
 
        } else {
            throw NullPointerException("未设置layout")
        }
    }
}