Android EditText for password with android:hint

2019-01-21 18:16发布

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?

9条回答
在下西门庆
2楼-- · 2019-01-21 19:10

Hint is displayed correctly with

android:inputType="textPassword"

and

android:gravity="center"

if you set also

android:ellipsize="start"
查看更多
3楼-- · 2019-01-21 19:12

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"

查看更多
疯言疯语
4楼-- · 2019-01-21 19:13

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="********"
    />
查看更多
登录 后发表回答