在Android的密码提示的字体 [英] Password hint font in Android

查看:342
本文介绍了在Android的密码提示的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个EditText在密码模式,似乎提示显示在不同的字体(信使报?)。我怎样才能避免这种情况?我想出现在相同的字体,当EditText上不处于密码模式的提示。

我的当前xml:

 <的EditText
机器人:提示=@字符串/ edt_password_hint
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:密码=真
机器人:单线=真/>
 

解决方案

改变字体在XML的提示文本没有工作对我来说无论是。我发现了两个不同的解决方案,其中第二个具有更好的行为对我来说:

1)删除安卓inputType =textPassword从您的XML文件,而在设置它在Java:

 的EditText密码=(EditText上)findViewById(R.id.password_text);
password.setTransformationMethod(新PasswordTransformationMethod());
 

通过这种方式,提示的字体看起来不错,但因为你正在输入的编辑字段,你没有看到以纯文本的每个字符会变成一个口令一个点之前。此外,在全屏使得输入时,这些点会不会出现,而是以明文形式passoword。

2)离开安卓inputType =textPassword在XML。在Java中,还设置了字体和passwordMethod:

 的EditText密码=(EditText上)findViewById(R.id.register_password_text);
password.setTypeface(Typeface.DEFAULT);
password.setTransformationMethod(新PasswordTransformationMethod());
 

这个方法给我的提示字体,我想,给我我想要的行为,密码点。

希望帮助!

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.

My current xml:

<EditText 
android:hint="@string/edt_password_hint"
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:password="true"
android:singleLine="true" />

解决方案

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) 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 passoword in clear text.

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.

Hope that helps!

这篇关于在Android的密码提示的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆