欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android中实现EditText密码显示隐藏的方法

程序员文章站 2024-02-23 20:32:04
在google发布了support:design:23+以后我们发现有这么一个东西textinputlayout,先看下效果图:

在google发布了support:design:23+以后我们发现有这么一个东西textinputlayout,先看下效果图:

Android中实现EditText密码显示隐藏的方法

<android.support.design.widget.textinputlayout
  android:id="@+id/pwdlayout"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  app:passwordtoggleenabled="true"
  >
  <edittext
  android:id="@+id/pwdedt"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="@string/edt_pwd_hint"
  android:maxlines="1"
  android:inputtype="textpassword" />
 </android.support.design.widget.textinputlayout>

只要在布局中添加属性app:passwordtoggleenabled=”true”就可以实现当edittext的inputtype=”textpassword”的时候在输入框的最右边就会显示眼睛一样的开关来显示和隐藏密码,需要的同学不妨试试看。

参考: