us2956
us2956

Reputation: 516

Android - EditText keyboard type programmatically

I try to set the keyboard type of an edit text.

When I use below code, it changes the font of the edit text's hint.

setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD);

So, I try another solution.

setTransformationMethod(new PasswordTransformationMethod());

I create an edit text. My password is shown on top of the keyboard.(looks like auto suggestion).

How can I set the keyboard type for password without changing the font of the text?

Upvotes: 1

Views: 5088

Answers (3)

Jaspreet Kaur
Jaspreet Kaur

Reputation: 1720

// this work for me, donot set android:inputType="textPassword" in your xml file and instead, set it in java
     <EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />


    editText.setTransformationMethod(new PasswordTransformationMethod());

Upvotes: -1

us2956
us2956

Reputation: 516

Solution is here:

typeface = edittext.getTypeface(); 
editText.setInputType(InputType.TYPE_CLASS_TEXT |InputType.TYPE_TEXT_VARIATION_PASSWORD);
editText.setTypeface(typeface);

Upvotes: 2

N.Moudgil
N.Moudgil

Reputation: 869

for Font issue you can try this :

    editText.setInputType(InputType.TYPE_CLASS_TEXT |InputType.TYPE_TEXT_VARIATION_PASSWORD);
    editText.setTypeface(Typeface.DEFAULT);

Upvotes: 4

Related Questions