Android : Typeface is changed when i apply password Type on EditText
Solution 1
The following might solve it for you.
pass.setTypeface(user.getTypeface());
Essentially it just passes the Typeface
of your username field and passes it as the Typeface
for your password field.
I found an explanation of this in the Dialogs API Guide.
Tip: By default, when you set an EditText element to use the
"textPassword"
input type, the font family is set to monospace, so you should change its font family to"sans-serif"
so that both text fields use a matching font style.
In otherwords, a fix that can be done in XML would be as follows:
<EditText
android:id="@+id/password"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:hint="@string/password"/>
Solution 2
For some reason I didn't have to set the transformation method so this may be a better solution. In MyActivity:
EditText editText_password = findViewById(R.id.edittext);
editText_password.setTransformationMethod(new PasswordTransformationMethod());
Solution 3
you can use android:hit, and setHitColor in your activity, it will not affect the normal input
Solution 4
Set the inputType as "text" in the xml,
<EditText
android:id="@+id/edtPassword"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password"
android:inputType="text"/>
Then make the EditText in the activity as
mEdtConfirmPassword = findViewById(R.id.edtPassword);
mEdtConfirmPassword.setTransformationMethod(new PasswordTransformationMethod());
![wawanopoulos](https://i.stack.imgur.com/zoHLk.jpg?s=256&g=1)
wawanopoulos
Updated on November 07, 2020Comments
-
wawanopoulos over 3 years
I use FloatLabel library (https://github.com/weddingparty/AndroidFloatLabel) to add a little animation when user begin to write something in an EditText Android.
My problem is that the typeface seems to be changed when i apply the password type to my EditText. I would like to keep the same typeface as normal. (see picture 1)
But when i add the following line to apply password type, the typeface of hint seems to be changed !
pass.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
-
Muhammad Babar over 9 years
fontFamily
is introduced in api level 16! what for 2.2? -
1mike12 over 8 yearsThis is exactly the solution. Without having to set thing in code with setTypeface() and setTransformationMethod(), which don't even work fully because the next letters that you type are hidden and not shown
-
Ravi Vaniya over 6 yearswhat is
user
? -
Jordan H about 5 yearsThis is the only thing that worked for me when using a custom font - set inputType back to text and then set the transformation