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:
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.
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
Scrolling Edittext Inside Scrollview
Ask for Password Before Uninstalling Application
Extracting Information from a Scanned Gs1-Type Barcode
Cannot Resolve Mapactivity Class on Android
Android Marshmallow: Changing Permissions at Run Time Crashes App
How to Create and Save a Screenshot from a Surfaceview
Android Spinner Error:Android.View.Windowmanager$Badtokenexception: Unable to Add Window
Ndk: How Include *.So Files in Androidstudio
Why Does Navigation Not Work in the Navigation Drawer Activity Template with Version 2.4.1
How to Animate a Slide in Notification View That Pushes the Content View Down
Sdcard Content Exist But Cant See Them
Multiple Dex Files Define Lcom/Google/Android/Gms/Internal/Zzau
How to Disable Proguard for Building My Android App
Which View Should Be Used for New Material Design Bottom Navigation
Android: Is Using Setcontentview Multiple Times Bad While Changing Layouts