62

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?

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
yjw
  • 3,394
  • 4
  • 20
  • 20

9 Answers9

89

Hint is displayed correctly with

android:inputType="textPassword"

and

android:gravity="center"

if you set also

android:ellipsize="start"
swiftBoy
  • 35,607
  • 26
  • 136
  • 135
mango
  • 926
  • 1
  • 6
  • 4
  • Thanks for that. Quite puzzling why ellipsize is something that can affect the visibility of the hint. I'm not seeing the train of thought behind this to help me understand this. Any suggestion? – yjw Nov 11 '11 at 04:15
  • 1
    There is none :) It's a platform bug afaik, although it has been there for years. – mango Nov 21 '11 at 07:51
24

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!

derekerdmann
  • 17,696
  • 11
  • 76
  • 110
yjw
  • 3,394
  • 4
  • 20
  • 20
7

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.

Manoj Fegde
  • 4,786
  • 15
  • 50
  • 95
3

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

rahul
  • 2,758
  • 5
  • 32
  • 53
2

If you set

android:inputType="textPassword"

this property and if you provide number as password example "1234567" it will take it as "123456/" the seventh character is not taken. Thats why instead of this approach use

android:password="true"

property which allows you to enter any type of password without any restriction.

If you want to provide hint use

android:hint="hint text goes here"

example:

android:hint="password"
swiftBoy
  • 35,607
  • 26
  • 136
  • 135
MobileEvangelist
  • 2,583
  • 1
  • 25
  • 36
2

Here is your answer:

There are different category for inputType so I used for pssword is textPaswword

<EditText
    android:inputType="textPassword"
    android:id="@+id/passwor"
    android:textColorHint="#ffffff"
    android:layout_marginRight="15dp"
    android:layout_marginLeft="15dp"
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:hint="********"
    />
Ashish Tiwari
  • 2,168
  • 4
  • 30
  • 54
2

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>
arghtype
  • 4,376
  • 11
  • 45
  • 60
Raj Padvi
  • 21
  • 2
1

android:hint="Enter your question" or something like this must work. I am using Relative layout with EditText as If you want to use password,say android:inputType="textPassword" for hiding characters and "textVisiblePassword" for showing what you enter as password.

Rashmi.B
  • 1,787
  • 2
  • 18
  • 34
  • Hi Rashmi, thanks for your answer. I'm wondering if you missed my question. I'm expecting an EditText with android:hint="password" and android:inputType="textPassword" to have the hint 'password' displayed when my Activity first loaded, but behaves like a password field when user starts entering password. However, this particular behavior which is what I observe previously with android:password is no longer the same with android:inputType. That's my issue here. On a side note, what's the use for "textVisiblePassword"? I'm not sure I see the need for this particular usage. – yjw Mar 22 '11 at 08:23
1

Actually, I found that if you put the the android:gravity="center" at the end of your xml line, the hint text shows up fine with the android:inputType="textVisiblePassword"

Lynn S
  • 369
  • 4
  • 6