Calligraphy: Password Hint text does not have correct font applied
If i try to use calligraphy for a password field as such:
<EditText
            style="@style/AppTheme.Font.Lgt"
            android:id="@+id/passwordText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="@dimens/text_size_med"
            android:hint="@string/password_hint"
            android:inputType="textPassword"
            android:text=""/>
It seems that the inputType attribute is forcing the hint into being monospaced (which seems to be odd, but normal android behavior with EditText). In this case, the font being applied by the style is ignored. Presumably because it is applied prior to android applying the inputType, and thus the typeface is getting overriden.
About this issue
- Original URL
- State: open
- Created 9 years ago
- Reactions: 4
- Comments: 16 (6 by maintainers)
@here @mattinger I try this way:
1.- remove android:inputType=“textPassword” from xml 2.- apply typeface using this great library @chrisjenx thanks 3.- set passwordtransformation in code: password.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); // No suggestions password.setTransformationMethod(PasswordTransformationMethod.getInstance());
DONE !!
My solution is to save the
Typefacebefore setting the input type and put it back afterwards.@Sanjay-F if you use TextView.setInputType() with any of:
…then Android applies a Monospace typeface.
Note: you need to bitwise OR the above variations with the appropriate:
…when calling TextView.setInputType() otherwise Android doesn’t change the transformation type.
If for example you are using a button to toggle a password to be visible or not, you’ll have to manually set the Typeface after each call to setInputType() if you want to apply a custom Typeface. When toggling password visibility Android appears to reset the cursor position to the start of the EditText, so this snippet also sets the cursor to the end of the EditText.
Setting the type face from another text field of the form, i.e the user name type face is the easiest and simple way to do this:
passwordField.setTypeface(usernameField.getTypeface());@QiiqeAzuara your solution with
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONScaused autocomplete to show up and it’s not safe IMHO. I tried withInputType.TYPE_TEXT_VARIATION_PASSWORDand it worked - both TextInputLayout and EditText use custom font, password is not visible and there is no autocomplete.The work around is the easy bit it’s all the hacky work arounds for every single weird view that I can’t support.
On Thu, 6 Oct 2016, 07:16 davweb, notifications@github.com wrote:
@chrisjenx thank you, I didn’t know it. So, now I can replace
TypefaceSpan typefaceSpan = new CustomTypefaceSpan(face);byCalligraphyTypefaceSpan typefaceSpan = TypefaceUtils.getSpan(face);No need to createCustomTypefaceSpanas it is done on the link I provided before.Final code to support a custom font for password EditText is: