Home » Android » android – Password hint font is different than other edittext fields

android – Password hint font is different than other edittext fields

Posted by: admin June 15, 2020 Leave a comment

Questions:
EditText password = (EditText) view.findViewById(R.id.etPassword);

    if (Build.VERSION.SDK_INT != android.os.Build.VERSION_CODES.KITKAT) {
        Typeface typeface = TypefaceUtil.overrideFont(getContext(), "SERIF", "fonts/calibri.ttf");
        password.setTypeface(typeface);
    }

And this is the XML layout for the TextInputLayout

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

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

I am trying to use this code but my password hint font style is different than which I had set.

How to&Answers:

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());

Answer:

Try this

<Edittext
            android:id="@+id/edtPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Password"
            android:inputType="text"
            android:textSize="14sp" />

Set android:inputType="text" in your edittext xml.

Set edtPassword.setTransformationMethod(new PasswordTransformationMethod()); in java file.

Works for me in custom font for edittext.

Answer:

use android:fontFamily="sans-serif"

Answer:

Hey if someone is using kotlin I hope this code helps you, it is working for me. I’m using
com.google.android.material.textfield.TextInputLayout
and androidx.appcompat.widget.AppCompatEditText

in kotlin:

// find the view
val etPassword = view.findViewById<AppCompatEditText>(R.id.etPassword)

// set the typeface to your choice
etPassword.typeface = Typeface.SANS_SERIF

// the set its transformationMethod to PasswordTransformationMethod
etPassword.transformationMethod = PasswordTransformationMethod()

this is my xml:

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/tilPassword"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:passwordToggleEnabled="true">


    <androidx.appcompat.widget.AppCompatEditText
        android:id="@+id/etPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</com.google.android.material.textfield.TextInputLayout>

Answer:

I am also face this problem.

You have to try this way, you will got solution.

XML code

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Password"
    android:id="@+id/password_text"/>

Java Code

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

Hope this will helps you…

Answer:

I observed that the font style of my Edittext was different when the input type was textPassword. Fixed this by using the fontFamily attribute.

Below is the code which I used in my layout:

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fontFamily="sans-serif"
    android:hint="My Password hint"
    android:inputType="textPassword" />