对于API16,正负按钮依次出现。而在API 19及以上版本中,它们属于同一行。更改字体不会更改位置。我怎样才能让两个按钮在同一行?
android - 在警报对话框 fragment 的同一行中设置正和负按钮-LMLPHP

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.resume_session)
            .setMessage(R.string.session_question)
            .setPositiveButton(R.string.continue_session, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    setDataAndStart(dataHelper, exDB);
                }
            })
            .setNegativeButton(R.string.restart_session, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    exDB.resetCurrentWorkoutRecords();
                    setDataAndStart(dataHelper, exDB);
                }
            });
    final AlertDialog pendingWorkoutAlert = builder.create();
    //check for dp size of the phone and then change font
    if (AppApplication.displayType.equals("normal")) {
        pendingWorkoutAlert.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                Button btnPositive = pendingWorkoutAlert.getButton(Dialog.BUTTON_POSITIVE);
                btnPositive.setTextSize(14);

                Button btnNegative = pendingWorkoutAlert.getButton(Dialog.BUTTON_NEGATIVE);
                btnNegative.setTextSize(14);
            }
        });
    }
    return pendingWorkoutAlert;

最佳答案

问题是,您没有指定自己的布局,因此android使用默认布局,因此您无法影响对话框内容的包装方式。
您可以使用AlertDialog.Builder#setView定义自己的布局。

关于android - 在警报对话框 fragment 的同一行中设置正和负按钮,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35988194/

10-10 22:57