First you have to add an AlertDialog
to your onCreate()
method in your Activity
.
After then You have to add a button to that AlertDialog
.
There are three types of button in AlertDialog
.
Positive
Negative
Neutral
Use any one of them.
Then when the button clicked you need to go to the website url, in some browser in the android device.
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.your-web-site-url.com"));
startActivity(browserIntent);
Try this:
final Context context = this;
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
// set title
alertDialogBuilder.setTitle("Your Title");
// set dialog message
alertDialogBuilder
.setMessage("Click to visit website!")
.setCancelable(false)
.setPositiveButton("Go to web site",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.your-web-site-url.com"));
startActivity(browserIntent);
}
}));
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();