Android EditText用于密码与android:提示

yjw*_*yjw 53 xml passwords android hint android-edittext

刚刚注意到android:password已被弃用,我们应该使用android:inputType.正在通过设置我的xml来试验它

android:inputType="textPassword" 
Run Code Online (Sandbox Code Playgroud)

确实它表现得像

android:password="true" 
Run Code Online (Sandbox Code Playgroud)

对于EditText,但似乎如果我使用android:inputType,android:hint将无效.EditText将为空白.使用android:password和android:hint时没有这样的问题.我在这里错过了关于android:inputType的东西吗?

小智 82

提示正确显示

android:inputType="textPassword"
Run Code Online (Sandbox Code Playgroud)

android:gravity="center"
Run Code Online (Sandbox Code Playgroud)

如果你也设置

android:ellipsize="start"
Run Code Online (Sandbox Code Playgroud)


yjw*_*yjw 24

只是偶然发现了答案.android:inputType="textPassword"确实与工作android:hint,一样android:password.唯一的区别是当我使用时android:gravity="center",如果我正在使用,提示将不会显示android:inputType.案件结案!


Man*_*gde 6

这是你的答案.我们可以同时使用两者.因为我使用它们并且它们工作正常.代码如下:

<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" />
Run Code Online (Sandbox Code Playgroud)

这会对你有所帮助.