Reputation: 2084
I am creating two edittext. All the attributes are same except input type. One is email and other is password. If I remove android:inputType
there is no change in width.
<EditText
android:id="@+id/edittext_email"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:background="@drawable/custom_edit"
android:ems="12"
android:hint="@string/email_address"
android:inputType="textEmailAddress"
android:paddingLeft="10dp" />
<EditText
android:id="@+id/edittext_password"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:background="@drawable/custom_edit"
android:ems="12"
android:hint="@string/password"
android:inputType="textPassword"
android:paddingLeft="10dp" />
Upvotes: 2
Views: 875
Reputation: 5731
Not only the width, but also the text face is also different for the two boxes. Its because of the input type password.
Either you can set text font in code as password.setTypeface(Typeface.DEFAULT);
or not to use wrap_content.
Upvotes: 1
Reputation: 5806
As you said, the problem is caused by setting the inputType to textPassword in your xml (note that it also changes the font of the text).
Try this solution:
1- Keep the inputType to password
2- Add the following code in the view that contains the editText:
EditText password = (EditText) findViewById(R.id.edittext_password);
password.setTypeface(Typeface.DEFAULT);
password.setTransformationMethod(new PasswordTransformationMethod());
This will actually fix the font, and, hopefully, the size of the edittext as well.
Upvotes: 6