Java tutorial
//package com.java2s; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.graphics.Color; import android.view.Gravity; import android.widget.TextView; public class Main { public static void showOkDialog(String title, String msg, Activity act) { AlertDialog.Builder dialog = new AlertDialog.Builder(act); if (title != null) { TextView dialogTitle = new TextView(act); dialogTitle.setText(title); dialogTitle.setPadding(10, 10, 10, 10); dialogTitle.setGravity(Gravity.CENTER); dialogTitle.setTextColor(Color.WHITE); dialogTitle.setTextSize(20); dialog.setCustomTitle(dialogTitle); } if (msg != null) { dialog.setMessage(msg); } dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.dismiss(); } }); AlertDialog dlg = dialog.show(); TextView messageText = (TextView) dlg.findViewById(android.R.id.message); messageText.setGravity(Gravity.CENTER); } }