[参考一篇博客进行修改](https://blog.csdn.net/maoruibin9035/article/details/79180621)
<LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><Buttonandroid:id="@+id/button_1"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="点击" /></LinearLayout>
class MainActivity : AppCompatActivity(){override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)button_1.setOnClickListener{AlertDialog.Builder(this).setMessage("成功").setTitle("对话框").setPositiveButton("确定", DialogInterface.OnClickListener { dialogInterface, i ->Toast.makeText(this,"对话框显示成功",Toast.LENGTH_LONG).show()}).setNeutralButton("取消", null).create().show()}}
}
编译并运行模拟器
按照箭头操作
成功显示对话框