How do I display an alert dialog on Android?

后端 未结 30 3059
清歌不尽
清歌不尽 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:34

    Alert dialog with edit text

    AlertDialog.Builder builder = new AlertDialog.Builder(context);//Context is activity context
    final EditText input = new EditText(context);
    builder.setTitle(getString(R.string.remove_item_dialog_title));
            builder.setMessage(getString(R.string.dialog_message_remove_item));
     builder.setTitle(getString(R.string.update_qty));
                builder.setMessage("");
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.MATCH_PARENT,
                        LinearLayout.LayoutParams.MATCH_PARENT);
                input.setLayoutParams(lp);
                input.setHint(getString(R.string.enter_qty));
                input.setTextColor(ContextCompat.getColor(context, R.color.textColor));
                input.setInputType(InputType.TYPE_CLASS_NUMBER);
                input.setText("String in edit text you want");
                builder.setView(input);
       builder.setPositiveButton(getString(android.R.string.ok),
                    (dialog, which) -> {
    
    //Positive button click event
      });
    
     builder.setNegativeButton(getString(android.R.string.cancel),
                    (dialog, which) -> {
    //Negative button click event
                    });
            AlertDialog dialog = builder.create();
            dialog.show();
    

提交回复
热议问题