Android Dialog Box without buttons

前端 未结 9 2488
余生分开走
余生分开走 2021-02-19 06:52

Can i create a dialog box without negative or positive buttons. That destroys it self after specific action?

 AlertDialog.Builder dialog_detect= new AlertDialog.         


        
相关标签:
9条回答
  • 2021-02-19 07:06

    to show dialog:-

    ProgressDialog pd = ProgressDialog.show(context,"TITLE","MSG");
    

    to dismiss

    pd.dismiss();
    
    0 讨论(0)
  • 2021-02-19 07:11

    You can try Custom Dialog design u r on Dialog and use it as u wish to use them

    final Dialog dialog= new Dialog(context);
    dialog.setContentView(R.layout.pre_confirmation_dailog); 
    dialog.setTitle("Details...");
    dialog.show();
    
    0 讨论(0)
  • 2021-02-19 07:11

    You can try custom dialog as you like

    Dialog dialog_help = new Dialog(this);
    dialog_help.setContentView(R.layout.title_multi_selectitems_dialog);
    EditText et_1 = (EditText) dialog_help.findViewById(R.id.et_help_1);
    dialog_help.setCancelable(true);
    dialog_help.setTitle("   Help   ");
    dialog_help.setCanceledOnTouchOutside(true);
    dialog_help.show();
    dialog_help.getWindow().setGravity(Gravity.CENTER);
    dialog_help.getWindow().setLayout(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
    
    0 讨论(0)
  • 2021-02-19 07:13

    You can do this very easily.

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
    
    // set title
    alertDialogBuilder.setTitle("Your Title");
    
    // set dialog message
    alertDialogBuilder.setMessage("Message here!").setCancelable(false);
    
    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();
    
    // show it
    alertDialog.show();
    
    // After some action
    alertDialog.dismiss();
    

    If you have a reference to the AlertDialog somewhere else, you can still call alertDialog.dismiss(). This closes the dialog.

    0 讨论(0)
  • 2021-02-19 07:19

    You can also write crocboy's code like this:

    AlertDialog alertDialog = new AlertDialog.Builder(context)    
        .setTitle("Your Title")
        .setMessage("Message here!")
        .setCancelable(false)
        .create();
    
    alertDialog.show();
    
    // After some action
    alertDialog.dismiss(); 
    

    It does exactly the same thing, it's just more compact.

    0 讨论(0)
  • 2021-02-19 07:23

    Really depends on what "action" is being performed:


     AlertDialog.Builder dialog_detect= new AlertDialog.Builder(MainActivity.this);
     dialog.setTitle("Detecting.....");
     dialog.setMessage("Please Wait");
     dialog.show();
    
     timeConsumingDetectMethod();
    
     dialog.dismiss();
    

    This way you get a frozen UI until timeConsumingDetectMethod() finishes.


    However, the following way runs the action in background, while a very responsive dialog is shown. Also, cancels the action when dialog is cancelled.

    AsyncTask<Void,Void,Void> task = new AsyncTask<Void, Void, Void>() {
    
            private AlertDialog dialog;
    
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                dialog= new AlertDialog.Builder(MainActivity.this);
                dialog.setTitle("Detecting.....");
                dialog.setMessage("Please Wait");
    
                dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialogInterface) {
                        cancel(true);
                    }
                });
    
                dialog.show();
            }
    
            @Override
            protected Void doInBackground(Void... voids) {
                timeConsumingDetectMethod();
                return null;
            }
    
            @Override
            protected void onPostExecute(Void aVoid) {
                super.onPostExecute(aVoid);
                dialog.dismiss();
            }
    
        }.execute();
    
    0 讨论(0)
提交回复
热议问题