1

i am working in a social app and while the user wants to edit their feeds i want to give them a pop up alert dialog from where the user can edit their post. I tried the following code but the result that gave was not good alert dialog

i want to change the color and want a better design .. what can be done for this

private void EditCurrentPost(String description)
    {
        AlertDialog.Builder builder =  new AlertDialog.Builder(ClickPostActivity.this);
        builder.setTitle("Edit post");
        final EditText inputField = new EditText(ClickPostActivity.this);
        inputField.setText(description);
        builder.setView(inputField);

        builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              ClickPostRef.child("description").setValue(inputField.getText().toString());
              Toast.makeText(ClickPostActivity.this,"Post Updated",Toast.LENGTH_SHORT).show();

            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
           dialog.cancel();
            }
        });
        Dialog dialog = builder.create();
        dialog.show();
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.holo_purple);
    }
Bob Snyder
  • 37,759
  • 6
  • 111
  • 158
mezohn adhikari
  • 87
  • 1
  • 3
  • 12

2 Answers2

2

There is a very simple way to make dialog with custom layout: Please review the code below:

final Dialog dialog = new Dialog(MainActivity.this);
    dialog.setContentView(R.layout.dialog_news_description);//Your custom layout
    TextView sometextview = dialog.findViewById(R.id.textView);// Textview in your custom layout
    Button somebutton = dialog.findViewById(R.id.button_done);// Button in your layout
    somebutton.setOnClickListener(new View.OnClickListener() {//on button click listener
        @Override
        public void onClick(View view) {
            //DO your job.... 
            //then...
            dialog.dismiss();//dismiss the dialog
        }
    });
    dialog.show();
Gourango Sutradhar
  • 1,461
  • 10
  • 16
1

You cannot change the default AlertDialog layout but you can inflate a custom layout to it. To start with you can check this post http://android-coding.blogspot.com/2011/07/create-custom-dialog-using.html

Rashid
  • 1,700
  • 1
  • 23
  • 56