Password Hint Font in Android

Password hint font is different than other edittext fields

addding to this, It works when the iandroid:inputType=" textPassword" is removed and adding app:passwordToggleEnabled="true"

<android.support.design.widget.TextInputLayout
android:id="@+id/inpPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/button_margin_small"
app:passwordToggleEnabled="true">

<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/set_pass"
android:maxLength="@integer/pass_max"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>

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

Password hint font in Android

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


  1. 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.

How to set hint text as password in Android

Yes Thank guys, your comments are useful always :)

It worked for me by doing simply

<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/sign_up_views_vertical_top_margin"
android:background="@drawable/edittext_border"
android:drawableLeft="@drawable/password_drawable"
android:drawablePadding="10dp"
android:hint="@string/sign_up_password"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:singleLine="true"
android:textColorHint="@android:color/black" />

strings.xml

<string name="sign_up_password">●●●●●●●●</string>

How to style hint for EditText with inputType set to textPassword in Android

Set Edittext Typeface default programmatically

password.setTypeface(Typeface.DEFAULT);

Password edittext hint text alignment on right side

Please refer to this post :

Android RTL password fields?

For API 17+ you can use

android:textAlignment="viewStart"

Error trying to change password hint font

Change the call of setContentView(R.layout.activity_main);

Call it just after super.onCreate(savedInstanceState);



When you're doing EditText pw = (EditText) findViewById(R.id.password);, findViewById "can't retrieve" the EditText that you have defined in your layout (because you call setContentView after) so findViewById returns null and when you're doing pw.setTypeface(Typeface.DEFAULT); it throws a NPE because pw is null.



Related Topics



Leave a reply



Submit