puzhibing
2026-08-21 5fa94b3718b4a78a4fcea4c97652b0ef20b7de3a
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")
        }
    }
}