【问题标题】:Password Hint font in android development [duplicate]android开发中的密码提示字体[重复]
【发布时间】:2014-07-27 21:55:53
【问题描述】:

当 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" />`

【问题讨论】:

标签: android passwords


【解决方案1】:

可能重复:Password hint font in Android

更改 xml 中的字体对我来说也不适用于提示文本。我找到了两种不同的解决方案,其中第二种对我来说效果更好:

1) 从您的 xml 文件中删除 android:password="true" ,然后在 java 中设置它:

EditText password = (EditText) findViewById(R.id.password_text);
password.setTransformationMethod(new PasswordTransformationMethod());

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

2) 将 android:password="true" 留在您的 xml 中。在Java中,ALSO设置字体和密码方法:

EditText password = (EditText) findViewById(R.id.register_password_text);
password.setTypeface(Typeface.DEFAULT);
password.setTransformationMethod(new PasswordTransformationMethod());

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

希望有帮助!

【讨论】:

    【解决方案2】:
    <EditText 
    android:hint="@string/edt_password_hint"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:password="true"
    android:singleLine="true" 
    android:fontFamily="Arial"
    />
    

    将最后一行添加到您的编辑文本中。 你可以使用任何你喜欢的字体。

    【讨论】:

      猜你喜欢
      • 2011-03-25
      • 1970-01-01
      • 2019-12-26
      • 2014-06-14
      • 2021-08-09
      • 1970-01-01
      • 1970-01-01
      • 2013-05-04
      • 1970-01-01
      相关资源
      最近更新 更多