Anko: how to make a custom alert in anko?

Created on 11 Jan 2018  路  4Comments  路  Source: Kotlin/anko

how to make a custom alert in anko?

kotlin

val builder = AlertDialog.Builder(this, R.style.AlertDialogCustom)
        val view = layoutInflater.inflate(R.layout.dialog_city, null)
        view.findViewById<TextView>(R.id.tv_close).setOnClickListener {
            btnShowDialog.isEnabled = true
            dialog.cancel()
        }
        builder.setView(view)
        dialog = builder.create()
        dialog.setOnCancelListener(object : DialogInterface.OnCancelListener {
            override fun onCancel(p0: DialogInterface?) {
                btnShowDialog.isEnabled = true
            }
        })
        dialog.show()

anko

 alert {
            layoutInflater.inflate(R.layout.dialog_city, null)
        }.show()

tvClose.setOnClickListener how to do in anko?

Most helpful comment

it's a simple as
val alert = with(activity) { alert { customView = vertivalLayout {} } } alert.show()

All 4 comments

You can add listeners as follows:

alert{
    layoutInflater.inflate(R.layout.dialog_city, null)
}.setOnCancelListener(...).show()

it's a simple as
val alert = with(activity) { alert { customView = vertivalLayout {} } } alert.show()

well, the theme where to enter the style file?

to Anko, how to set the theme of alert

Was this page helpful?
0 / 5 - 0 ratings