Add bigger margin to EditText in Android AlertDialog

I have an EditText inside an AlertDialog. It looks like this.

enter image description here

See where it says tddjdjck and how it is indented quite a lot. That is what I want (I used setPadding with left and right set to 50), but I also want the blue line under it to be indented too. How do I do that?

The code I am using is below:

            final AlertDialog.Builder alert = new AlertDialog.Builder(thisActivity);
            final EditText input = new EditText(thisActivity);
            input.setSingleLine();
            input.setPadding(50, 0, 50, 0);

            alert.setTitle("by...");
            alert.setMessage("enter the name of the person who did:");
            alert.setView(input);
            alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String value = input.getText().toString().trim();

                }
            });

            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });
            alert.show();  

Thank you


Solution 1:

final AlertDialog.Builder alert = new AlertDialog.Builder(thisActivity);
final EditText input = new EditText(thisActivity);
input.setSingleLine();
FrameLayout container = new FrameLayout(thisActivity);
FrameLayout.LayoutParams params = new  FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.leftMargin = getResources().getDimensionPixelSize(R.dimen.dialog_margin);
input.setLayoutParams(params);
container.addView(input);
alert.setTitle("by...");
alert.setMessage("test message");
alert.setView(container);

Make sure you add another line to your dimens.xml resource file, such as

<dimen name="dialog_margin">20dp</dimen>

Solution 2:

You can pass spacing parameter in setView method

alert.setView(view ,left_space , top_space , right_space , bottom_space);

So,in your case you can try this

alert.setView(input , 50 ,0, 50 , 0);