当EditText处于密码模式时,提示似乎以不同的字体显示(courier ?)我该如何避免这种情况?我想提示出现在相同的字体,当EditText不是在密码模式。

我当前的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中:

<EditText
    android:id="@+id/password_edit_field"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="Password"
    android:inputType="textPassword" />

在活动中:

EditText password = (EditText) findViewById( R.id.password_edit_field );
password.setTypeface( Typeface.DEFAULT );

其他回答

使用书法图书馆。

然后它仍然不会用正确的字体更新密码字段。所以在代码中,而不是在xml中:

Typeface typeface_temp = editText.getTypeface();
editText.setInputType(inputType); /*whatever inputType you want like "TYPE_TEXT_FLAG_NO_SUGGESTIONS"*/
//font is now messed up ..set it back with the below call
editText.setTypeface(typeface_temp); 

改变xml中的字体对我的提示文本也不起作用。我找到了两种不同的解决方案,其中第二种对我来说表现更好:

将android:inputType="textPassword"从你的xml文件中删除,改为在java中设置它: EditText password = (EditText) findViewById(R.id.password_text); 密码。setTransformationMethod(新PasswordTransformationMethod ());

使用这种方法,提示字体看起来不错,但当您在编辑字段中输入时,在它变成密码点之前,您不会看到纯文本中的每个字符。此外,全屏输入时,不会出现圆点,而是以明文显示密码。

在xml中保留android:inputType="textPassword"。在Java中,设置字体和密码方法: EditText password = (EditText) findViewById(R.id.register_password_text); password.setTypeface (Typeface.DEFAULT); 密码。setTransformationMethod(新PasswordTransformationMethod ());

这种方法给了我想要的提示字体,并给了我想要的使用密码点的行为。

也许是一个奇怪的例子,但我已经做过实验,并发现:

password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
password.setTransformationMethod(new PasswordTransformationMethod());

改变了提示字体的大小,而不是字体本身!这仍然是一种不受欢迎的效果。奇怪的是,相反的操作:

password.setTransformationMethod(new PasswordTransformationMethod());
password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);

保持相同的字体大小。

像上面一样,但要确保字段在XML中没有粗体样式,因为即使有上面的修复,它们看起来也不会相同!

这是如何使输入密码有提示,不转换为*和默认字体!!

关于XML:

android:inputType="textPassword"
android:gravity="center"
android:ellipsize="start"
android:hint="Input Password !."

活动介绍:

inputPassword.setTypeface(Typeface.DEFAULT);

感谢芒果和rjjr的洞察力:D。