0

Hello senior developer.

recently I create alertdialog.

I know title size, message size controll

but I don't know controll button text size

How controll button text size ?

I must this format please thanks.

 View view = getLayoutInflater().inflate(R.layout.connecting_error_dialog, null);
        TextView txtTitle = (TextView) view.findViewById(R.id.title);
        txtTitle.setTextSize(40);
        txtTitle.setTextColor(Color.RED);
        txtTitle.setText("fail");

        TextView message = (TextView) view.findViewById(R.id.message);
        message.setTextSize(30);
        message.setText("dddddd");

        AlertDialog.Builder builder = new AlertDialog.Builder(Connectingreceiver.this);
        builder.setView(view)
                .setCancelable(false)
                .setPositiveButton("ok",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                moveTaskToBack(true);
                                finish();
                                android.os.Process.killProcess(android.os.Process.myPid());
                            }
                        });
        AlertDialog alertDialog = builder.create();
        alertDialog.show();





<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:padding="10dp">
    <LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView android:id="@+id/title"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center"
              android:text="HelloAlert!"/>
    <TextView android:id="@+id/message"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:paddingTop="10dip"/>
</LinearLayout>

조현욱
  • 31
  • 8
  • What have you tried? What exactly is going wrong? Do you get any errors? What are those errors? What have you tried to do to fix those errors? What happened when you did that? Remember to include these things when you make your question. Follow this guide to make sure your questions are of high quality: https://stackoverflow.com/help/how-to-ask – Matt C Apr 01 '16 at 02:25

1 Answers1

3

The alert dialog needs to be created first and then it's elements become accessible to be changed.

final AlertDialog alert = builder.create();
alert.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
    Button btnPositive = alert.getButton(Dialog.BUTTON_POSITIVE);
    btnPositive.setTextSize("desired font size");

    Button btnNegative = alert.getButton(Dialog.BUTTON_NEGATIVE);
    btnNegative.setTextSize("desired font size");
  }
});

return alert;
suku
  • 10,507
  • 16
  • 75
  • 120