Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Alert text size in alert dialog

The alert message by default is too big for specific devices with little screens and I want to set it to a custom dp

My alert is something like this

OnClickListener addNewItemListener = new OnClickListener() {
                public void onClick(View v) {
                    AlertDialog.Builder alert = new AlertDialog.Builder(
                            MyActivity.this);

                    LinearLayout myLayout= new LinearLayout(MyActivity.this);
                    myLayout.setOrientation(LinearLayout.VERTICAL);

                    alert.setTitle(R.string.add_title);
                    alert.setMessage(R.string.add_message);

                    final TextView t1 = new TextView(MyActivity.this);
                    t1.setText("Name");
                    final EditText input1 = new EditText(MyActivity.this);
                    myLayout.addView(t1);
                    myLayout.addView(input1);
                    alert.setView(myLayout);
                    alert.setPositiveButton(R.string.cancel,
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int whichButton) {
                                }
                            });
                    alert.setNegativeButton(R.string.ok,
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int whichButton) {
                                    try {
                                        ....
                                    } catch (RuntimeException e) {
                                        Alerts.DatiErrati(MyActivity.this);
                                    }

                                }
                            });
                    alert.show();
                }
            };

How could I set the text size of the alert message?

like image 826
AndreaF Avatar asked Mar 22 '23 10:03

AndreaF


2 Answers

EDIT 2:

This is the best method you can go with

AlertDialog.Builder builder = new Builder(this);
builder.setMessage("Record and Images will be deleted?")
        .setTitle("MyTitle")
        .setCancelable(true)
        .setPositiveButton("Yes",
                        new DialogInterface.OnClickListener()
                        {

                            public void onClick(DialogInterface dialog,
                                    int id)
                            {

                                dialog.cancel();
                                finish();
                            }
                        })
                .setNegativeButton("No",
                        new DialogInterface.OnClickListener()
                        {

                            public void onClick(DialogInterface dialog,
                                    int id)
                            {
                                dialog.cancel();
                            }
                        });
        AlertDialog dialog = builder.create();
        dialog.show();
        TextView textView = (TextView) dialog.findViewById(android.R.id.message);
        textView.setTextSize(40);

You can use the following to get bigger text only

  alert.setMessage(Html.fromHtml("<Big>"+getString(R.string.add_message)+"</Big>"));

Note: you can use more big's for more bigger text

like image 59
Trikaldarshiii Avatar answered Mar 29 '23 11:03

Trikaldarshiii


Try this:

AlertDialog dialog = new AlertDialog.Builder(this).setMessage("Hello world").show();
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
textView.setTextSize(40);
like image 43
Evgeni Roitburg Avatar answered Mar 29 '23 11:03

Evgeni Roitburg