Android UI How to - Create about AlertDialog








Question

We would like to know how to create about AlertDialog.

Answer

The following code shows a convenient method to create an About Dialog.

We can set the email, subject information on the About dialog.

/*from   w w w .  j  a  va2 s. co  m*/
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;

public class Main {
  public static AlertDialog getAboutDialog(final Activity activity){
    String message = "line \n line \n line \n line\n!";
    
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle("About") //
         .setIcon(android.R.drawable.ic_dialog_info) //
         .setMessage(message) //
           .setCancelable(false) //
           .setPositiveButton("Send Feedback", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                 Intent intent = new Intent(android.content.Intent.ACTION_SEND);  
                 intent.setType("plain/text");  
                 intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"youraddress@your server.com"});  
                 intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Feedback on Android App");  
                 activity.startActivity(intent);
               }
           }).setNegativeButton("Close", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                 dialog.dismiss();
               }
           });
    return builder.create();
  }
}