Just wondered, am I the only one to encounter this "strange" behavior.
我只是想知道,我是唯一一个遇到这种“奇怪”行为的人吗?
When placing an EditText inside my activity and setting its inputType="textPassword" as follow:
在我的活动中放置EditText并设置它的inputType="textPassword"如下:
<EditText android:text="" android:id="@+id/EditText01"
android:hint="This is a hint" android:inputType="textPassword"
android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
The hint is displayed with bigger/double spaces between the words.
提示用两个单词之间的大/双空格显示。
If I remove the inputType attribute it all goes back to normal. I couldn't find a known issue regarding this behavior.
如果我删除inputType属性,它将恢复正常。我找不到关于这种行为的已知问题。
BTW- If you wonder why this is important (it isn't that much) try putting two EditText widgets one below the other and set the inputType of one of them to "textpassword" it doesn't look good. Any idea on how to change the password or the other edittexts to use the same format ?
顺便说一下,如果你想知道为什么这很重要(不是那么多),试着把两个EditText小部件放在另一个下面,然后把其中一个的inputType设置为“textpassword”,这看起来不太好。您知道如何更改密码或其他edittexts以使用相同的格式吗?
Thanks
谢谢
PS. The question was added here first: http://groups.google.com/group/android-developers/browse_thread/thread/88738bb8d8046f6f but I didn't find an answer.
这个问题是先在这里添加的:http://groups.google.com/group/android- developers/browse_thread/88738bb8d8046f6f,但我没有找到答案。
2 个解决方案
#1
8
It happens because typeface automatically setted to monospace in case of password field. Setting android:typeface="normal"
on password field doesn't helps.
之所以会出现这种情况,是因为在出现密码字段时,字体会自动设置为monospace。设置android:在密码字段上的字体="normal"没有帮助。
Here code from TextView sources:
这里的代码来自TextView源代码:
if (password) {
setTransformationMethod(PasswordTransformationMethod.getInstance());
typefaceIndex = MONOSPACE;
} else if ((mInputType&(EditorInfo.TYPE_MASK_CLASS
|EditorInfo.TYPE_MASK_VARIATION))
== (EditorInfo.TYPE_CLASS_TEXT
|EditorInfo.TYPE_TEXT_VARIATION_PASSWORD)) {
typefaceIndex = MONOSPACE;
}
I can't find solution without implementing custom control with overriden typeface for hint.
如果不使用overriden字体为提示实现自定义控件,我就找不到解决方案。
P.S.: There is one solution, but it is not always acceptable - to set typeface to monospace on other EditText's.
注::有一种解决方案,但并不总是可以接受的——在其他EditText上将字体设置为monospace。
#2
4
Doing mEditText.setTypeface(Typeface.DEFAULT);
fixes the problem for me.
做mEditText.setTypeface(Typeface.DEFAULT);帮我解决问题。
#1
8
It happens because typeface automatically setted to monospace in case of password field. Setting android:typeface="normal"
on password field doesn't helps.
之所以会出现这种情况,是因为在出现密码字段时,字体会自动设置为monospace。设置android:在密码字段上的字体="normal"没有帮助。
Here code from TextView sources:
这里的代码来自TextView源代码:
if (password) {
setTransformationMethod(PasswordTransformationMethod.getInstance());
typefaceIndex = MONOSPACE;
} else if ((mInputType&(EditorInfo.TYPE_MASK_CLASS
|EditorInfo.TYPE_MASK_VARIATION))
== (EditorInfo.TYPE_CLASS_TEXT
|EditorInfo.TYPE_TEXT_VARIATION_PASSWORD)) {
typefaceIndex = MONOSPACE;
}
I can't find solution without implementing custom control with overriden typeface for hint.
如果不使用overriden字体为提示实现自定义控件,我就找不到解决方案。
P.S.: There is one solution, but it is not always acceptable - to set typeface to monospace on other EditText's.
注::有一种解决方案,但并不总是可以接受的——在其他EditText上将字体设置为monospace。
#2
4
Doing mEditText.setTypeface(Typeface.DEFAULT);
fixes the problem for me.
做mEditText.setTypeface(Typeface.DEFAULT);帮我解决问题。