Android(安卓)EditText 密码隐藏或可见
16lz
2021-01-24
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());
完事
更多相关文章
- LinearLayout和RelativeLayout的属性差异
- Android(安卓)activity 参数传递
- ScrollView can host only one direct child
- 对话框AlertDialog的使用
- Android之WebView控件简单使用总结
- android recyclerview adaper封装
- android按钮事件触发拨号器
- Android通知栏详解
- Android(安卓)多点触摸 multi-touch