anko icon indicating copy to clipboard operation
anko copied to clipboard

YesButton and NoButton text

Open marcosvbras opened this issue 6 years ago • 3 comments

Is It possible to change YesButton and NoButton text?

marcosvbras avatar Dec 04 '18 12:12 marcosvbras

I assume that you are referring to the AlertBuilder class since AlertDialogBuilder is deprecated.

For AlertBuilder, the yesButton and noButton are nothing but simple extension methods on top of positiveButton and negativeButton:

inline fun AlertBuilder<*>.yesButton(noinline handler: (dialog: DialogInterface) -> Unit) =
    positiveButton(android.R.string.yes, handler)

inline fun AlertBuilder<*>.noButton(noinline handler: (dialog: DialogInterface) -> Unit) =
    negativeButton(android.R.string.no, handler)

so I think you can just call the positiveButton and negativeButton with the text you like.

iceboundrock avatar Dec 18 '18 06:12 iceboundrock

I assume that you are referring to the AlertBuilder class since AlertDialogBuilder is deprecated.

For AlertBuilder, the yesButton and noButton are nothing but simple extension methods on top of positiveButton and negativeButton:

inline fun AlertBuilder<*>.yesButton(noinline handler: (dialog: DialogInterface) -> Unit) =
    positiveButton(android.R.string.yes, handler)

inline fun AlertBuilder<*>.noButton(noinline handler: (dialog: DialogInterface) -> Unit) =
    negativeButton(android.R.string.no, handler)

so I think you can just call the positiveButton and negativeButton with the text you like.

How can I call this in Anko dialogs?

marcosvbras avatar Dec 19 '18 14:12 marcosvbras

Something like this:

alert {
    positiveButton("YES!!!", {})
    negativeButton("NOPE!!!, {})
    // something else ...
}

And you can use resource id instead of literal string.

iceboundrock avatar Dec 19 '18 18:12 iceboundrock