Changing font size into an AlertDialog

Viewed 64879

I am trying to put some loooong text into an AlertDialog. The only issue the default font size that is really too big, so I want to make it smaller.

Here are all the workaround I tried and their issues.

Workaround 1) Using a TextView and myView.setTextSize(12);

final TextView myView = new TextView(getApplicationContext());
myView.setText(myLongText);
myView.setTextSize(12);
final AlertDialog d = new AlertDialog.Builder(context)
    .setPositiveButton(android.R.string.ok, null)
.setTitle(myTitle)
.setView(myView)
.create();

Issues: Layout is not scrolling

Workaround 2) making TextView scrollable.

message.setMovementMethod(LinkMovementMethod.getInstance());

Issues: Layout is scrolling, bute there is no "inertia" (don't know how to call that.. But I guess you understand.)

Workaround 3) Using a Scrollview.

That's what I am going to try, but I cannot believe there are no easier solutions...

7 Answers

This works in 2020. I have tested this in Android 10

AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.YourStyle) //Style is only needed if you want to customize look&feel
            .setTitle(R.string.title)
            .setMessage(R.string.message)
            .setPositiveButton(R.string.accept, null);
    AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(dialog -> {
        //The following is to style dialog message
        TextView message = alertDialog.findViewById(android.R.id.message);
        if (message != null) {
            message.setTextSize(12);
            message.setTextColor(getColor(R.color.yellow));
        }
        //The following is to style dialog title. Note that id is alertTitle
        TextView title = alertDialog.findViewById(R.id.alertTitle);
        if (title != null) {
            title.setTextColor(getColor(R.color.black));
        }
    });
    alertDialog.show();
               AlertDialog.Builder builder = new 
                AlertDialog.Builder(YourActivity.this);
                builder.setTitle("Your Title");
                builder.setMessage("Your Message");
                builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        // Your Positive Function
                    }
                });
                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        // Your Negative Function
                    }
                });
                builder.show();
Related