Androidのパスワードヒントフォント 質問する

Androidのパスワードヒントフォント 質問する

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

ベストアンサー1

XML の書体を変更しても、ヒント テキストは機能しませんでした。2 つの異なる解決策を見つけましたが、2 番目の方法の方が動作が良好です。

  1. xml ファイルから削除しandroid:inputType="textPassword"、代わりに Java で設定します。

    EditText パスワード = (EditText) findViewById(R.id.password_text); password.setTransformationMethod(新しい PasswordTransformationMethod());

このアプローチでは、ヒント フォントは見栄えがよいですが、編集フィールドに入力しているときに、パスワード ドットに変換される前に各文字がプレーン テキストで表示されません。また、全画面で入力する場合、ドットは表示されず、パスワードがプレーン テキストで表示されます。

  1. android:inputType="textPassword"xml に残しておきます。Java では、書体とパスワード メソッドも設定します。

    EditText パスワード = (EditText) findViewById(R.id.register_password_text); password.setTypeface(Typeface.DEFAULT); password.setTransformationMethod(new PasswordTransformationMethod());

このアプローチにより、必要なヒント フォントが得られ、パスワード ドットで必要な動作も得られました。

おすすめ記事