Question: I've created an AlertDialog with an EditText in my Android app, but the default margins look really off. I've tried to specify margins as follows:

```
  android.support.v7.app.AlertDialog.Builder builder =  new android.support.v7.app.AlertDialog.Builder(SpinActivity.this);
            builder.setTitle("Edit Spin Tags");
            builder.setMessage("(separate tags with commas)");

            // set input
            int margin = 10;
            final EditText input = new EditText(SpinActivity.this);
            input.setSingleLine();
            input.setText(spinTags.toString().replace("[", "").replace("]", ""));
            builder.setView(input, margin, 0, margin, 0);

```

However, from the image below, you can see that it is not applying the desired effect.

[![enter image description here](https://i.stack.imgur.com/lkGnp.png)](https://i.stack.imgur.com/lkGnp.png)

Other options I've tried including placing the input in a LinearLayout and setting the margins using LayoutParams before setting the AlertDialog view to the LinearLayout.

**How do I set the margins for an EditText in an AlertDialog?**

Answer: 
Actually your solution is working perfectly, except that `builder.setView(input, margin, 0, margin, 0);` takes arguments in "pixel" values. So a value of 20 is very small. Either use a higher value for margin e.g. in the 100s. or use this function to convert from dp to pixels 

```
public static int dpToPx(int dp)
{
    return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
}

```

and then,

```
int margin = dpToPx(20);

```
Define your Edittext in a different layout file while setting proper margins in that layout. Inflate that layout and then set it as view for dialog.