无法显示Common Dialog。我是Kotlin的新手。有没有人遇到过这个问题?
我试过了
class CommonStaticClass {
fun showCommonPopUp(activity: Context, msg: String,drawable: Int): Dialog {
val metrics = activity.resources.displayMetrics
val dev_width = metrics.widthPixels
val dev_height = metrics.heightPixels
val dialogCommon = Dialog(activity)
dialogCommon.window.setBackgroundDrawable(ColorDrawable(android.graphics.Color.TRANSPARENT))
dialogCommon.window.requestFeature(Window.FEATURE_NO_TITLE)
dialogCommon.setContentView(R.layout.dialog_alert)
dialogCommon.setCancelable(false)
dialogCommon.setCanceledOnTouchOutside(false)
dialogCommon.window.setLayout((dev_width* 85)/ 100, (dev_height* 25) / 100)
val tv_headerObj = dialogCommon.findViewById(R.id.txt_header) as TextView
val img_smileOBJ = dialogCommon.findViewById(R.id.img_smile) as ImageView
img_smileOBJ.setImageResource(drawable)
tv_headerObj.text = msg + ""
dialogCommon.show()
return dialogCommon
}
}
Kotlin班
val commonDIALOG= commonDialogOBJ!!.showCommonPopUp(getActivity()!!,"Your session has expired. Please log in",R.drawable.ic_sad)
commonDIALOG.show()
我宣布了
private var commonDialogOBJ : CommonStaticClass? = null
commonDialogOBJ = CommonStaticClass()
答案 0 :(得分:0)
它为我工作。
以我的xml为例
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txt_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
然后
val commonDialogOBJ: CommonStaticClass by lazy { CommonStaticClass() }
commonDialogOBJ.showCommonPopUp(this, "Hello world");
你的班级代码都很完美。但一切都将是透明的