When an EditText is in password mode, it seems that the hint is shown in a different font (courrier?). How can I avoid this? I would like the hint to appear in the same font that when the EditText is not in password mode.
My current xml:
<EditText
android:hint="@string/edt_password_hint"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:password="true"
android:singleLine="true" />
The setTransformationMethod approach breaks android:imeOption for me, and allows carriage returns to be typed into the password field. Instead I'm doing this:
And am not setting android:password="true" in XML.
I recently added the ability to change toggle monospace on/off to a extension of EditText specifically for passwords it may help some people. It doesn't use
android:fontFamily
so is compatible <16.I use this solution to toggle the Typeface depending on hint visibility. It's similar to Joe's answer, but extending EditText instead:
I know this may be the older one but I have humped into something related to this issue when I used
InputType
andapp:passwordToggleEnabled="true"
together.So, writing this, as it may help someone over here.
I want to use a custom font to password field along with
app:passwordToggleEnabled
option for my password input field. But in 27.1.1 (while writing this) support library, it was crashing.So the code was like below,
Above code do not have
inputType
defined in XMLAnd in Java,
setTransformationMethod
will help me acquire the properties oftextPassword
input type and also I'm happy my custom font style.But the below-mentioned crash happened in all API levels with 27.1.1 support library.
This was crashing due to the
onRestoreInstanceState
insideTextInputLayout
class.Reproduce Steps: Toggle the password visibility and minimize the app and open from the recent apps. Uh,ho Crashed!
All I needed is default password toggle option (using support library) and custom font in the password input field.
After some time, figured out by doing as below,
In XML, added
android:inputType="textPassword"
In above java code,
I acquired the custom typeface from username
EditText
and applied it toTextInputLayout
of the password field. Now you don't need to set the typeface explicitly to the passwordEditText
as it will acquire theTextInputLayout
property.Also, I removed
password.setTransformationMethod(new PasswordTransformationMethod());
By doing this way,
passwordToggleEnabled
is working, the custom font is also applied and bye-bye to the crash. Hope this issue will be fixed in upcoming support releases.A weird case perhaps, but I have experimented with this and found out that:
changed the size of the font of the hint instead of the font itself! This is still an undesired effect. Strangely enough, the reverse operation:
Keeps the same font size.