demo

1.单个按钮对话弹窗

private void showTip() {
    AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setPositiveButton("确定", (dialog1, which) -> dialog1.dismiss());
    AlertDialog alertDialog = dialog.create();
    TextView title = new TextView(this);
    title.setText("提示");
    title.setPadding(10, 30, 10, 10);
    title.setGravity(Gravity.CENTER);
    title.setTextSize(18);
    title.setTextColor(Color.BLACK);
    alertDialog.setCustomTitle(title);
    alertDialog.setMessage("怎么一到周末,都没MM来约我呢?\r\n" +
            "五四运动都快90年了,还搞得这么保守。她们怎么越来越不长进了呢?\n" +
            "再看看一千多年前的唐朝,那时的女装多前卫,多时尚。真是一代不如一代,一代不如一代啊。\n" +
            "一个早上我都在长吁短叹中度过!");
    alertDialog.setCancelable(false);
    alertDialog.show();
    Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
    LinearLayout.LayoutParams cancelBtnPara = (LinearLayout.LayoutParams) button.getLayoutParams();
    //设置按钮的大小
    cancelBtnPara.height = LinearLayout.LayoutParams.WRAP_CONTENT;
    cancelBtnPara.width = LinearLayout.LayoutParams.MATCH_PARENT;
    //设置文字居中
    cancelBtnPara.gravity = Gravity.CENTER;
    //设置按钮左上右下的距离
    cancelBtnPara.setMargins(100, 20, 100, 20);
    button.setLayoutParams(cancelBtnPara);
   // button.setBackground(ContextCompat.getDrawable(this, R.drawable.ic_launcher_background));
    button.setTextColor(ContextCompat.getColor(this, R.color.white));
    button.setTextSize(16);
}

demo

2.单个按钮对话框示例

public void openDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("这是标题");
    builder.setMessage("落雁沉鱼 兰质蕙心 明眸皓齿 螓首蛾眉 水木清华 爽心悦目 天生丽质 天香国色");
    builder.setPositiveButton("好的", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            Log.v("1","=============");
            // 默认会调用这个方法,不用手动添加
             dialog.dismiss();
        }
    });
    //builder.setNegativeButton("绝代佳人", null);
    AlertDialog dilog = builder.create();
    dilog.setCancelable(false);
    dilog.show();
}