Android Dialog Box without buttons

前端 未结 9 2528
余生分开走
余生分开走 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: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.

提交回复
热议问题