Changing font size into an AlertDialog

You can actually get access to the message's TextView pretty easily, and then change it's size. I tested with a bigger size, but you could use whatever size you want. The text will scroll nicely as it already does. The view's id is android.R.id.message

    AlertDialog dialog = new AlertDialog.Builder(this).setMessage("Hello world").show();
    TextView textView = (TextView) dialog.findViewById(android.R.id.message);
    textView.setTextSize(40);

This is probably a cleaner solution, though I'm not sure if there's a risk that the TextView could be null or not.


For Buttons:

  final AlertDialog ad = new AlertDialog.Builder(mainScreen)
.setPositiveButton("OK", null) 
.setNegativeButton("Cancel", null).create();

ad.setOnShowListener(new DialogInterface.OnShowListener() {
                                            @Override
                                            public void onShow(DialogInterface dialog) {
                                                int textSize = (int) Helper.getDimen(mainScreen, R.dimen.textSize12);
                                                ad.getButton(Dialog.BUTTON_POSITIVE).setTextSize(textSize);
                                                ad.getButton(Dialog.BUTTON_NEGATIVE).setTextSize(textSize);
                                            }


                                      });

ad.show();

I am using the following code to change the title and message text for AlertDialog…

final int alertTitle = ctx.getResources().getIdentifier("alertTitle", "id", "android");
setTitleFont((TextView) dlg.findViewById(alertTitle));
setBodyFont((TextView) dlg.findViewById(android.R.id.message));

… making sure that I check for null in my setTitleFont and setBodyFont methods.


Here is my solution... you need to create the scroll container, then add the TextView inside the ScrollView just as you would in the XML layout.

AlertDialog alertDialog = new AlertDialog.Builder(this).create();
String str = getString(R.string.upgrade_notes); 
final ScrollView s_view = new ScrollView(getApplicationContext());
final TextView t_view = new TextView(getApplicationContext());
t_view.setText(str);
t_view.setTextSize(14);     
s_view.addView(t_view);
alertDialog.setTitle("Upgrade notes!");
alertDialog.setView(s_view);