Android中的密码提示字体 [英] Password hint font in Android
问题描述
当 EditText 处于密码模式时,提示似乎以不同的字体(信使?)显示.我怎样才能避免这种情况?我希望提示以与 EditText 未处于密码模式时相同的字体显示.
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.
我当前的 xml:
<EditText
android:hint="@string/edt_password_hint"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:password="true"
android:singleLine="true" />
推荐答案
更改 xml 中的字体对我来说对提示文本也不起作用.我找到了两种不同的解决方案,其中第二种对我来说效果更好:
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) 从您的 xml 文件中删除 android:inputType="textPassword"
,而是在 java 中进行设置:
1) Remove android:inputType="textPassword"
from your xml file and instead, in set it in java:
EditText password = (EditText) findViewById(R.id.password_text);
password.setTransformationMethod(new PasswordTransformationMethod());
使用这种方法,提示字体看起来不错,但是当您在该编辑字段中输入时,您在变成密码点之前看不到纯文本中的每个字符.同样在全屏输入时,点不会出现,而是明文密码.
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 password in clear text.
2) 将 android:inputType="textPassword"
保留在您的 xml 中.在 Java 中,还需要设置字体和密码方法:
2) Leave android:inputType="textPassword"
in your xml. In Java, ALSO set the typeface and passwordMethod:
EditText password = (EditText) findViewById(R.id.register_password_text);
password.setTypeface(Typeface.DEFAULT);
password.setTransformationMethod(new PasswordTransformationMethod());
这种方法为我提供了我想要的提示字体,并通过密码点为我提供了我想要的行为.
This approach gave me the hint font I wanted AND gives me the behavior I want with the password dots.
希望有帮助!
这篇关于Android中的密码提示字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!