android中的警告对话框

时间:2012-05-15 10:38:37

标签: android

即时通讯在我的应用程序中使用警告对话框,当出现警告对话框时,我的整个活动都会显示为背景并出现黑色。我希望当出现对话框时,我的活动看起来就像以前一样,我不喜欢不管任何背景情况?

3 个答案:

答案 0 :(得分:4)

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

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

自定义对话框: android dialog transparent

AlertBox:Set Transparent Window in AlertDialog box

答案 1 :(得分: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();      }   } 

答案 2 :(得分: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();
            }
        });