How to change Anko alert positive/negative button color?
Asked Answered
A

1

6

For example I have the next alert creation way:

  alert(message, title) {
        positiveButton(R.string.alert_dialog_btn_ok) {
        }
    }.show()

I want to change the color of positive button to green, and in future set red negative button.

Can I do this without creating custom DSL views inside the alert?

Angele answered 18/7, 2018 at 8:4 Comment(0)
E
12
            alert("message", "title") {
                positiveButton("ok") {}
                negativeButton("nope") {}
            }.show().apply {
                getButton(AlertDialog.BUTTON_POSITIVE)?.let { it.textColor = Color.GREEN }
                getButton(AlertDialog.BUTTON_NEGATIVE)?.let { it.textColor = Color.RED }
            }

enter image description here

Expertise answered 18/7, 2018 at 8:19 Comment(2)
Thank you! It seems like a slight hack for me, but for now it works and does what I need.Restless
getButton() doesn't seem to exist anymore. I get "unresolved reference".Hokku

© 2022 - 2024 — McMap. All rights reserved.