最近在开发中遇到了,需要将密码框设置为显示和隐藏的需求,翻阅相关文档得到了答案,现在分享代码如下:
<EditText
android:id="@+id/hotspotpsd_edt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:inputType="textPassword"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_alignParentTop="true"
android:layout_marginRight="@dimen/dp_10"
android:layout_toRightOf="@id/left_view"/>
2.设置显示和隐藏
display_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
if(isChecked){
psd_edt.setTransformationMethod(HideReturnsTransformationMethod.getInstance());//显示密码}else{
psd_edt.setTransformationMethod(PasswordTransformationMethod.getInstance());//隐藏密码}}});