Hello Android
代码
1button.setOnClickListener { 2 val alertDialog = AlertDialog.Builder(this) 3 alertDialog.setTitle("提示") 4 alertDialog.setIcon(R.mipmap.ic_launcher) 5 val message = alertDialog.setMessage("HelloWorld") 6 alertDialog.setPositiveButton("确定" 7 /** 8 * 确定操作 9 */ 10 ) { paramAnonymousDialogInterface, paramAnonymousInt -> } 11 alertDialog.setNegativeButton("取消" 12 /** 13 * 取消操作 14 */ 15 ) { paramAnonymousDialogInterface, paramAnonymousInt -> } 16 17 /*** 18 * 设置点击返回键不会消失 19 * */ 20 alertDialog.setCancelable(false).create() 21 22 alertDialog.show() 23 24 val intent = Intent() 25 intent.action = Intent.ACTION_CALL 26 intent.data = Uri.parse("tel://119") 27 startActivity(intent) 28 }
###备注
//创建对象
val alertDialog = AlertDialog.Builder(this)
//设置对话框标题
alertDialog.setTitle("标题")
//设置图标
alertDialog.setIcon(R.mipmap.ic_launcher)
//设置内容
val message = alertDialog.setMessage("Hello Android")
//设置点击返回键对话框不消失
alertDialog.setCancelable(false).create()
//显示对话框
alertDialog.show()
控件id.setOnClickListener{
///事件内容
}
对话框对象AlertDialog
对话框引用android.support.v7.app.AlertDialog