Android:当我在EditText上应用密码类型时,字体已更改 [英] Android : Typeface is changed when i apply password Type on EditText
问题描述
我使用 FloatLabel 库( https://github.com/weddingparty/AndroidFloatLabel ),以便在用户开始在EditText Android中编写内容时添加一些动画.
I use FloatLabel library (https://github.com/weddingparty/AndroidFloatLabel) to add a little animation when user begin to write something in an EditText Android.
我的问题是,当我将密码类型应用于EditText时,字体似乎已更改.我想保持与正常字体相同的字体. (见图1)
My problem is that the typeface seems to be changed when i apply the password type to my EditText. I would like to keep the same typeface as normal. (see picture 1)
但是当我添加以下行来应用密码类型时,提示的字体似乎已更改!
But when i add the following line to apply password type, the typeface of hint seems to be changed !
pass.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
推荐答案
以下内容可能会为您解决.
The following might solve it for you.
pass.setTypeface(user.getTypeface());
基本上,它只是传递用户名字段的Typeface
并将其作为密码字段的Typeface
传递.
Essentially it just passes the Typeface
of your username field and passes it as the Typeface
for your password field.
我在 Dialogs API指南中找到了对此的解释.
I found an explanation of this in the Dialogs API Guide.
提示:默认情况下,当您将EditText元素设置为使用
"textPassword"
输入类型,字体系列设置为等宽,因此您 应该将其字体系列更改为"sans-serif"
,以便两个文本字段 使用匹配的字体样式.
Tip: By default, when you set an EditText element to use the
"textPassword"
input type, the font family is set to monospace, so you should change its font family to"sans-serif"
so that both text fields use a matching font style.
换句话说,可以用XML完成的修复如下:
In otherwords, a fix that can be done in XML would be as follows:
<EditText
android:id="@+id/password"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:hint="@string/password"/>
这篇关于Android:当我在EditText上应用密码类型时,字体已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!