Introduction:
In Android application development, buttons could be
programmed to perform some actions (such as navigating to another screen,
showing toast message, closing the app, among others) when the user taps or
clicks on them.
In this article, we will learn how to make a button to
perform the action of displaying an alert message to the user. This would be
achieved using a composable function called AlertDialog. Note that we will be
demonstrating this with the 'Click Here to Proceed' button located inside the
‘DemoScreen’ composable function in our 'Demo One' Android project from my
previous article.
Demonstration:
First, we will open the 'Demo One' project.
‘Demo One’ project is now opened as shown in Figure 1.
§ 'onDismissRequest' parameter
which will hide the dialog when the user presses the back button of the device
or any part of the screen outside the dialog.
§ 'title' which will display the
title of our alert message (for example 'CONFIRM').
§ 'text' which will display our
main alert message. To make the text scrollable (in case you have long
statements as your alert message), we will apply 'verticalScroll' modifier with
'rememberScrollState() function. Our alert message will be “Hello User! To navigate
to the next page, tap on NEXT button. Thank you.”
§ 'confirmButton' which will
hide the dialog (by simply setting the value of 'showAlertMessage' to false),
and perform the specified action in it when tapped. We will make the background
color of the button to be black, and set the text color to white, and make the
font weight to be bold.
Conclusion:
Comments
Post a Comment