60

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

android:inputType="textPassword" 

确实它的行为像

android:password="true" 

对于 EditText,但似乎如果我使用 android:inputType,android:hint 将不起作用。EditText 将为空白。使用 android:password 和 android:hint 时没有这样的问题。我在这里遗漏了一些关于 android:inputType 的内容吗?

4

9 回答 9

87

提示正确显示

android:inputType="textPassword"

android:gravity="center"

如果你也设置

android:ellipsize="start"
于 2011-11-10T11:02:01.747 回答
24

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

于 2011-03-25T16:47:04.340 回答
7

这是你的答案。我们可以同时使用两者。正如我使用的那样,它们工作正常。代码如下:

<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" />

这将对您有所帮助。

于 2012-12-29T11:45:35.043 回答
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...

于 2011-10-24T17:41:49.067 回答
2

如果你设置

android:inputType="textPassword"

此属性,如果您提供数字作为密码示例“1234567”,它会将其视为“123456/”,不采用第七个字符。这就是为什么而不是这种方法使用

android:password="true"

属性,允许您输入任何类型的密码,没有任何限制。

如果你想提供提示使用

android:hint="hint text goes here"

例子:

android:hint="password"
于 2012-05-15T12:37:32.507 回答
2

这是你的答案:

有不同的类别,inputType所以我用于 pssword 是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="********"
    />
于 2016-06-01T10:49:07.450 回答
2

提示文字不粗体,我尝试下面的代码。

当我更改inputtype=email时,其他编辑文本为粗体。但是当我将输入类型更改为时password,提示是正常的。

我需要将提示文本加粗,我的代码是:

 <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>
于 2017-01-18T10:17:24.560 回答
1

android:hint="Enter your question" 或类似的东西必须有效。我正在使用带有 EditText 的相对布局,如果你想使用密码,比如 android:inputType="textPassword" 用于隐藏字符,"textVisiblePassword" 用于显示你输入的密码。

于 2011-03-22T07:48:12.210 回答
1

实际上,我发现如果您将 android:gravity="center" 放在 xml 行的末尾,提示文本会很好地显示 android:inputType="textVisiblePassword"

于 2011-09-29T21:04:19.140 回答