Android EditText for password with android:hint
Solution 1
Just stumbled on the answer. android:inputType="textPassword"
does work with android:hint
, same as android:password
. The only difference is when I use android:gravity="center"
, the hint will not show if I'm using android:inputType
. Case closed!
Solution 2
Hint is displayed correctly with
android:inputType="textPassword"
and
android:gravity="center"
if you set also
android:ellipsize="start"
Solution 3
Here is your answer. We can use both simultaniously. As i used both and they are working fine. The code is as follows:
<EditText
android:id="@+id/edittext_password_la"
android:layout_below="@+id/edittext_username_la"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dip"
android:inputType="textPassword"
android:hint="@string/string_password" />
This will help you.
Solution 4
I had the same issue and found a solution :
Previous code:
<EditText
android:layout_height="wrap_content"
android:gravity="center"
android:inputType ="password"
android:layout_width="fill_parent"
android:id="@+id/password"
android:hint="password"
android:maxLines="1">
</EditText>
Solution:
<EditText
android:layout_height="wrap_content"
android:gravity="center"
android:password="true"
android:layout_width="fill_parent"
android:id="@+id/password"
android:hint="password"
android:maxLines="1">
</EditText>
The previous code does not show the 'hint', but when I changed it to the last one it started showing...
hope this be helpful to someone...
Solution 5
Hint text not bold, I try to below code.
When I change inputtype=email
, other edittext is bold. But when I change input type to password
, hint is normal.
I need hint text to be bold, my code is:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="56dp"
app:theme="@style/Widget.Design.TextInputLayout"
>
<EditText
android:id="@+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:textStyle="bold"
android:inputType="textPassword"
android:textColor="@color/White"
style="@style/Base.TextAppearance.AppCompat.Small"
android:drawableLeft="@drawable/ic_password"
android:drawablePadding="10dp"
/>
</android.support.design.widget.TextInputLayout>
yjw
Updated on March 31, 2020Comments
-
yjw about 4 years
Just noticed that android:password has been deprecated, and we should be using android:inputType. Was experimenting with it by setting in my xml
android:inputType="textPassword"
Indeed it behaves like
android:password="true"
for EditText, but it seems that if I use android:inputType, android:hint will not work. The EditText will be blank. There is no such issues when using android:password with android:hint. Am I missing something here about android:inputType?