1

我在我的应用程序中使用了一个警报对话框,当出现警报对话框时,我的整个活动进入后台并出现黑色。我希望当对话框出现时,我的活动看起来像以前一样,我不想任何背景场景?

4

3 回答 3

4

您需要为您的对话框使用透明标志。但可能您需要为其创建自定义对话框:

Dialog mDialog = new Dialog(mContext, android.R.style.Theme_Translucent);

自定义对话框: android 对话框透明

AlertBox:在 AlertDialog 框中设置透明窗口

于 2012-05-15T10:42:34.513 回答
2

尝试这个:

 public class CustomDialog extends Dialog implements OnClickListener {      
  Button button_home,button_cancel,button_resume;     
    public GamePauseMenu(Context context) {          
      super(context,R.style.Theme_Transparent);      
      }     


    public void show(int bg) {              
             super.show();         
           setContentView(R.layout.custdialog);       
            button_resume = (Button)findViewById(R.id.imageButton1);                  button_resume.setOnClickListener(this);    
     }     public void onClick(View v) {         cancel();      }   } 
于 2012-05-15T10:49:07.780 回答
0
 b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(
                        MainActivity.this);

// Setting Dialog Title
                alertDialog2.setTitle("Confirm Delete...");

// Setting Dialog Message
                alertDialog2.setMessage("Are you sure you want delete this file?");

// Setting Icon to Dialog
               // alertDialog2.setIcon(R.drawable.delete);

// Setting Positive "Yes" Btn
                alertDialog2.setPositiveButton("YES",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                // Write your code here to execute after dialog
                                Toast.makeText(getApplicationContext(),
                                        "You clicked on YES", Toast.LENGTH_SHORT)
                                        .show();
                            }
                        });

// Setting Negative "NO" Btn
                alertDialog2.setNegativeButton("NO",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                // Write your code here to execute after dialog
                                Toast.makeText(getApplicationContext(),
                                        "You clicked on NO", Toast.LENGTH_SHORT)
                                        .show();
                                dialog.cancel();
                            }
                        });

// Showing Alert Dialog
                alertDialog2.show();
            }
        });
于 2018-04-23T15:29:52.100 回答