Android EditText 密码隐藏或可见

  • 问题
  • 解决
  • 完事

问题

很常见的需求,点击一个按钮,隐藏或可见输入密码。

解决

布局:

<EditText   android:id="@+id/edt_password"   style="@style/Base.Widget.MaterialComponents.TextInputEditText"   android:layout_width="wrap_content"   android:layout_height="match_parent"   android:layout_marginLeft="@dimen/def_padding_left_right"   android:background="@null"   android:hint="@string/voice_link_network_wifi_password"   android:inputType="textPassword"   android:singleLine="true"   android:textColor="@color/text_normal_color"   android:textSize="@dimen/def_text_size" />

代码:

    /**     * 显示密码     * @param show     */    public void setSeePassword(boolean show) {        imgSee.setSelected(show);        edtPassword.setTransformationMethod(show?                HideReturnsTransformationMethod.getInstance() :                PasswordTransformationMethod.getInstance());    }

显示密码使用:

edtPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());

隐藏密码使用:

edtPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());

完事

更多相关文章

  1. LinearLayout和RelativeLayout的属性差异
  2. Android(安卓)activity 参数传递
  3. ScrollView can host only one direct child
  4. 对话框AlertDialog的使用
  5. Android之WebView控件简单使用总结
  6. android recyclerview adaper封装
  7. android按钮事件触发拨号器
  8. Android通知栏详解
  9. Android(安卓)多点触摸 multi-touch

随机推荐

  1. android秒表计时代码
  2. Android如何实现ListView的Item松开渐变
  3. Android日历只显示年月,只显示年
  4. Android(安卓)短信发送器
  5. The "Android" command is deprecated.
  6. Android关于常用正则号码类Util
  7. android计算器布局(TableLayout)
  8. Android(安卓)ndk 入门4 - C++实现
  9. Android显示网络图片相关实现方法浅谈
  10. Android(安卓)RecyclerView