progquester
progquester

Reputation: 1776

Can I distinguish between these two dismiss actions for alertdialog in jetpack compose?

I am a beginner of Jetpack compose. Now in my app screen, an AlertDialog is used to show some information to user.

According to doc, onDismissRequest is invoked when the user clicks outside the dialog or on the back button.

But I just want to dismiss it when back button is pressed, but not dissmiss when outside touched, how can I distinguish between them?

Upvotes: 5

Views: 2098

Answers (1)

Abhimanyu
Abhimanyu

Reputation: 14857

I just want to dismiss it when the back button is pressed, but not dismiss when outside touched

Use the properties attribute in AlertDialog like this.

AlertDialog(
    properties = DialogProperties(
        dismissOnClickOutside = false,
        dismissOnBackPress = true,
    ),
)

Upvotes: 8

Related Questions