Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法正确显示对话框_Android_Android Alertdialog - Fatal编程技术网

Android 无法正确显示对话框

Android 无法正确显示对话框,android,android-alertdialog,Android,Android Alertdialog,我正在开发一个应用程序,在这个应用程序中,我在单击按钮时从片段中调用一个对话框,但我的问题是,当我单击按钮时,对话框出现,但它以暗淡的颜色显示。当我再次点击对话框时,它的背景变成了白色。所以,我只想知道为什么会这样 从按钮上的片段调用对话框的代码单击 sms = (ImageView) v.findViewById(R.id.sms); sms.setOnClickListener(new View.OnClickListener() { @Override

我正在开发一个应用程序,在这个应用程序中,我在单击按钮时从片段中调用一个对话框,但我的问题是,当我单击按钮时,对话框出现,但它以暗淡的颜色显示。当我再次点击对话框时,它的背景变成了白色。所以,我只想知道为什么会这样

从按钮上的片段调用对话框的代码单击

       sms = (ImageView) v.findViewById(R.id.sms);
    sms.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (!admin_id.equals("0") && status.equals("A")) {
                DialogSMS dialogSMS = new DialogSMS(getActivity(), getContext());
                dialogSMS.show();
            } else {
                Toast.makeText(getActivity(), getResources().getString(R.string.disable_click), Toast.LENGTH_SHORT).show();

            }

        }

    });
对话框代码

    public class DialogSMS extends Dialog {

Context context;
ProgressDialog progressDialog;
SharedPreferences sharedPreferences;
SharedPreferences.Editor editor;
public static final String MY_PREF = "pref";
public static final String IS_SMS_SUBSCRIBE = "sms_status";
EditText etPostalCode;
EditText phoneNumber;
Dialog d;


public DialogSMS(Activity a, Context context) {
    super(a);
    this.context = context;
}


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    progressDialog = new ProgressDialog(context);

    sharedPreferences = context.getSharedPreferences(MY_PREF, Context.MODE_PRIVATE);

    AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
    alertDialog.setMessage(R.string.app_sms_dialog_msg);
    alertDialog.setPositiveButton(R.string.app_close_dialog_msg_yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

            SessionManager session = new SessionManager(context);

            if (session.isSmsSubscribed()) {

                AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
                alertDialog.setMessage(R.string.app_sms_unsubscribe);
                alertDialog.setPositiveButton(R.string.app_close_dialog_msg_yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {

                        unSubscribeSMS();
                        dialog.cancel();
                    }
                });
                alertDialog.setNegativeButton(R.string.app_close_dialog_msg_no, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                alertDialog.show();


            } else {
                d = new Dialog(getContext());
                d.setContentView(R.layout.dialog_select_sms);
                etPostalCode = (EditText) d.findViewById(R.id.etPostalCode);
                phoneNumber = (EditText) d.findViewById(R.id.phoneNumber);


                Button btnSend = (Button) d.findViewById(R.id.btnSend);
               d.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

                btnSend.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {


                        String mobile = phoneNumber.getText().toString();
                        String postalCode = etPostalCode.getText().toString();

                        validateFields(mobile, postalCode);

                        //subscribeSMS(postalCode, mobile);
                        // d.cancel();
                    }
                });
                d.show();
                dialog.cancel();

            }
        }
    });
    alertDialog.setNegativeButton(R.string.app_close_dialog_msg_no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    alertDialog.show();
}
现在是对话框首次出现时的屏幕截图链接

打开弹出窗口时的黑色屏幕截图:

再次单击对话框时显示白色对话框:

使用
对话框。取消()
而不是
对话框。取消()

我只是想知道为什么会这样

这里,

将显示一个对话框,在对话框内,您还将创建AlertDialog并再次显示

AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setMessage(R.string.app_sms_dialog_msg);
--------------------------
alertDialog.show();
当您单击对话框时,它将取消一组对话框

实际上,您不需要在DialogSMS中创建AlertDialog

如果需要AlertDialog,那么为什么要显示该对话框?

*这可能会帮助你-* 把你的if-else条件带进去

sms.setOnClickListener

在对话中表达你的愿望

AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setMessage(R.string.app_sms_dialog_msg);
--------------------------
alertDialog.show();