开发者

Is there any widget for password entry?

I was tryin to find any class to define a password field? How can we do that? Do we have a class for that or 开发者_JAVA技巧some method to edittext?


There are a couple of ways of doing this.

The first (apparently) deprecated, is to set this property on the widget in your layout resource file

android:password="true"

From code this is equivalent to calling:

myEditTextWidget.setTransformationMethod(new PasswordTransformationMethod());

(note that this also gives you the flexibility to supply your own implementation of the TransformationMethod interface).

The second mechanism is to set this property:

android:inputType="textPassword"

again, equivalent to calling:

myEditTextWidget.setInputType(InputType.TYPE_CLASS_TEXT |
                              InputType.TYPE_TEXT_VARIATION_PASSWORD);


Better to use the inputType property, the password one is now deprecated.

<EditText android:id="@+id/password" android:inputType="textPassword"/>


In the xml layout file try assigning this property to your edittext...

android:password="true"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜