Open mattinger opened 9 years ago
v2.1.0
when i use
etPasword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
i meet the same problem help...any body. ;(
@mattinger @Sanjay-F I haven't had a chance to look into this. I would guess that setTypeface
does not apply to the password texts, but not sure.
@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.
mCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
int type = checked ? InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD : InputType.TYPE_TEXT_VARIATION_PASSWORD;
mPassword.setInputType(InputType.TYPE_CLASS_TEXT | type);
mPassword.setTypeface(customTypeface);
mPassword.setSelection(mPassword.length());
}
});
Wow nice work.
On Mon, 7 Sep 2015 21:52 Dave Jones notifications@github.com wrote:
@Sanjay-F https://github.com/Sanjay-F if you use TextView.setInputType() with any of:
- InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
- InputType.TYPE_TEXT_VARIATION_PASSWORD
- InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD
- InputType.TYPE_NUMBER_VARIATION_PASSWORD ...then Android [applies])( http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.2.1_r1.2/android/widget/TextView.java#TextView.setInputType%28int%29) a Monospace typeface.
Note: you need to bitwise OR the above variations with the appropriate:
- InputType.TYPE_CLASS_TEXT
- InputType.TYPE_CLASS_NUMBER 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.
mCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { int type = checked ? InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD : InputType.TYPE_TEXT_VARIATION_PASSWORD; mPassword.setInputType(InputType.TYPE_CLASS_TEXT | type); mPassword.setTypeface(customTypeface); mPassword.setSelection(mPassword.length()); } });
— Reply to this email directly or view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/186#issuecomment-138376055 .
@fingertricks thxxx very much!
@Sanjay-F you're welcome! I had solved that issue myself just last week.
In fact since Monday I found another tweak: you can call getSelectionStart() prior to the call to setInputType() and then use that to restore the cursor position with setSelection(). Just check that getSelectionStart() returns >= 0 though. This is preferable to moving the cursor to the end of the password field when toggling visibility.
You might also be able to do something with getTypeface(), but I haven't had time to look into that.
I've found the same problem when using TextInputLayout. I can set the correct Typeface of the EditText but the TextInputLayout remains with monospace.
Do you know any workaround I could take?
Thanks in advance
For those who still face the same issue: http://stackoverflow.com/a/35322532/1808829
@saqada there is a TypefaceSpannable in Calligraphy
if you wan't want to write your own .
@chrisjenx thank you, I didn't know it. So, now I can replace TypefaceSpan typefaceSpan = new CustomTypefaceSpan(face);
by CalligraphyTypefaceSpan typefaceSpan = TypefaceUtils.getSpan(face);
No need to create CustomTypefaceSpan
as it is done on the link I provided before.
Final code to support a custom font for password EditText is:
Typeface face = Typeface.createFromAsset(getAssets(), CalligraphyConfig.get().getFontPath());
EditText passwordEdittext = new EditText(getApplicationContext());
passwordEdittext.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
passwordEdittext.setTypeface(face, Typeface.ITALIC); // or Typeface.NORMAL or any other
CalligraphyTypefaceSpan typefaceSpan = TypefaceUtils.getSpan(face);
SpannableString spannableString = new SpannableString("Hint text");
spannableString.setSpan(typefaceSpan, 0, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
passwordEdittext.setHint(spannableString);
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());
Will InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS also ignore the setTypeface?
My solution is to save the Typeface
before setting the input type and put it back afterwards.
Typeface typeface = editText.getTypeface();
editText.setInputType(inputType);
editText.setTypeface(typeface);
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:
My solution is to save the Typeface before setting the input type and put it back afterwards.
Typeface typeface = editText.getTypeface(); editText.setInputType(inputType); editText.setTypeface(typeface);
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/186#issuecomment-251876299, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHRsVrLzTzfqdkgBDYbeNlLcgiNCv9Nks5qxJJQgaJpZM4FOV-W .
@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 !!
@QiiqeAzuara your solution with InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
caused autocomplete to show up and it's not safe IMHO.
I tried with InputType.TYPE_TEXT_VARIATION_PASSWORD
and it worked - both TextInputLayout and EditText use custom font, password is not visible and there is no autocomplete.
If i try to use calligraphy for a password field as such:
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.