Hello Android
代碼
button.setOnClickListener { val alertDialog = AlertDialog.Builder(this) alertDialog.setTitle("提示") alertDialog.setIcon(R.mipmap.ic_launcher) val message = alertDialog.setMessage("HelloWorld") alertDialog.setPositiveButton("確定" /** * 確定操作 */ ) { paramAnonymousDialogInterface, paramAnonymousInt -> } alertDialog.setNegativeButton("取消" /** * 取消操作 */ ) { paramAnonymousDialogInterface, paramAnonymousInt -> } /*** * 設置點擊返回鍵不會消失 * */ alertDialog.setCancelable(false).create() alertDialog.show() val intent = Intent() intent.action = Intent.ACTION_CALL intent.data = Uri.parse("tel://119") startActivity(intent) }
備註
//創建對象
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