1

I have a problem with the padding of a EditText from an alertDialog. I want it to not touch the sides but it does despite the setPadding I put..

Here's my code:

EditText temp = new EditText(this);
        temp.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
        temp.setPadding(10, 10, 10, 10);
        final EditText input = temp;
        new AlertDialog.Builder(LoginActivity.this).setTitle(getString(R.string.login_forgotpw_title))
                .setMessage(getString(R.string.login_forgotpw_message)).setView(input)

I thought it would do the job, but here's the result

It should not touch the sides

Thank you

dequec64
  • 883
  • 1
  • 7
  • 25

3 Answers3

1

I had the same problem. I resolved putting the editText inside a LinearLayout and adding padding to this LinearLayout. I don't know yet how to resolve it without doing that but it works.

1

You can set margin to edit text, if you tried to set a bigger padding and not worked.

Corina Gheorghe
  • 198
  • 1
  • 9
0

Try this :

LinearLayout baseLayout = new LinearLayout(this);
baseLayout.setOrientation(LinearLayout.VERTICAL);
baseLayout.setPadding(10, 10, 10, 10);

EditText temp = new EditText(this);
temp.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
temp.setPadding(10, 10, 10, 10);
final EditText input = temp;

baseLayout.addView(input);

new AlertDialog.Builder(LoginActivity.this)
    .setTitle(getString(R.string.login_forgotpw_title))
    .setMessage(getString(R.string.login_forgotpw_message))
    .setView(baseLayout)
    .create()
    .show();

Comment if you have issues understanding...

Arnab Jain
  • 247
  • 1
  • 5