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" />
You can also use a custom Widget. It's very simple and it doesn't clutter your Activity/Fragment code.
Here's the code:
And your XML will look like this:
The answer manisha provided does work, but it leaves the password field in a nonstandard state compared to the default. That is, the default fontface then applies also to the password field, including both the dot replacements and the preview characters that appears before being replaced with the dots (as well as when it is a "visible password" field).
To fix this and make it 1) look and act exactly like the default
textPassword
input type, but also 2) allow the hint text to appear in a default (non-monospace) font, you need to have aTextWatcher
on the field that can toggle the fontface properly back and forth betweenTypeface.DEFAULT
andTypeface.MONOSPACE
based on whether it is empty or not. I created a helper class that can be used to accomplish that:Then to make use of it, all you need to do is call the
register(View)
static method. Everything else is automatic (including skipping the workaround if the view does not require it!):Changing the typeface in xml didn't work on the hint text for me either. I found two different solutions, the second of which has better behavior for me:
1) Remove
android:inputType="textPassword"
from your xml file and instead, in set it in java:With this approach, the hint font looks good but as you're typing in that edit field, you don't see each character in plain text before it turns into a password dot. Also when making input in fullscreen, the dots will not appear, but the passoword in clear text.
2) Leave
android:inputType="textPassword"
in your xml. In Java, ALSO set the typeface and passwordMethod:This approach gave me the hint font I wanted AND gives me the behavior I want with the password dots.
Hope that helps!
There are many way for solving this problem but each way have pros and cons. Here is my testing
I only face this font problem in some device (list at the end of my answer) when enable input password by
If I use
android:inputType="textPassword"
, this problem don't happenedSomething I have tried
1) Use
setTransformationMethod
insteadinputType
2) Use
Typeface.DEFAULT
sans-serif-light
is a default font for allView
in my application => aftersetTypeface(Typeface.DEFAULT)
, theEditText
font still look different in some device3) Use
android:fontFamily="sans-serif"
MY SOLUTION
Testing
Some device face font problem
Some device not face font problem
I found this useful tip from Dialogs Guide
For example
like the above but make sure the fields do not have the bold style in xml as they will never look the same even with the above fix!