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

Ajil O.
  • 6,562
  • 5
  • 40
  • 72
Ruchita Sharma
  • 279
  • 2
  • 7
  • You are Using `android:inputType="textPassword"` so that it's showing different font.remove this line `android:inputType="textPassword"` check it once. – Gowthaman M Aug 17 '17 at 14:01
  • Please explain from what is it different and provide relevant code – Vega Aug 17 '17 at 14:01
  • Have a look at this [answer](https://stackoverflow.com/a/35322532/6891637) – Ajil O. Aug 17 '17 at 14:05
  • Possible duplicate of [change font for editText hint](https://stackoverflow.com/questions/13251990/change-font-for-edittext-hint) – Ajil O. Aug 17 '17 at 14:07

6 Answers6

16

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());
Ruchita Sharma
  • 279
  • 2
  • 7
11

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.

Velayutham M
  • 1,119
  • 14
  • 18
3

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>
raquezha
  • 283
  • 1
  • 2
  • 13
2

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

Raja
  • 2,775
  • 2
  • 19
  • 31
2

use android:fontFamily="sans-serif"

Luvnish Monga
  • 7,072
  • 3
  • 23
  • 30
0

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" />
Sanket Mendon
  • 403
  • 5
  • 11