조현욱
조현욱

Reputation: 31

How controll alertdialog button text size on android?

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>

Upvotes: 0

Views: 1452

Answers (1)

suku
suku

Reputation: 10937

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;

Upvotes: 4

Related Questions