How do I display an alert dialog on Android?

后端 未结 30 3296
清歌不尽
清歌不尽 2020-11-22 03:02

I want to display a dialog/popup window with a message to the user that shows \"Are you sure you want to delete this entry?\" with one button that says \'Delete\'. When

30条回答
  •  忘掉有多难
    2020-11-22 03:33

    you may try this way also, it will provide you material style dialogs

    private void showDialog()
    {
        String text2 = "Medi Notification";//for custom title color
    
        AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
        builder.setTitle(Html.fromHtml(text2));
    
        String text3 = "You can complete your profile now or start using the app and come back later";//for custom message
        builder.setMessage(Html.fromHtml(text3));
    
        builder.setPositiveButton("DELETE", new DialogInterface.OnClickListener()
        {
            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                toast = Toast.makeText(getApplicationContext(), "DELETE", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();              
            }
        });
    
        builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener()
        {
            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                toast = Toast.makeText(getApplicationContext(), "CANCEL", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            }
        });
        builder.show();
    }
    

提交回复
热议问题