您好,登錄后才能下訂單哦!
這篇文章主要介紹了Android開發(fā)EditText如何實(shí)現(xiàn)密碼顯示隱藏的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡(jiǎn)單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇Android開發(fā)EditText如何實(shí)現(xiàn)密碼顯示隱藏文章都會(huì)有所收獲,下面我們一起來看看吧。
關(guān)鍵類TextView.setTransformationMethod(TransformationMethod method),其中TransformationMethod 有兩個(gè)子類:
HideReturnsTransformationMethod 隱藏回車
PasswordTransformationMethod 密碼類型
關(guān)鍵代碼:
@OnClick(R.id.iv_psw_eye) void clickPswEye() { int tag = Integer.parseInt(pswEyeIV.getTag().toString()); if (tag == 1) {//顯示密碼 pswEyeIV.setTag(2); pswEyeIV.setImageResource(R.mipmap.icon_psw_not_eye); passwordET.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } else {//隱藏密碼 pswEyeIV.setTag(1); pswEyeIV.setImageResource(R.mipmap.icon_psw_eye); passwordET.setTransformationMethod(PasswordTransformationMethod.getInstance()); } }
我用ImageView的Tag屬性存儲(chǔ)當(dāng)前密碼輸入框的類型,1是密碼類型,2是顯示類型。布局組件關(guān)鍵代碼如下:
<RelativeLayout android:layout_width="match_parent" android:layout_height="45dp" android:layout_gravity="center" android:layout_marginTop="26dp" android:background="@drawable/bg_edit_login" android:paddingLeft="26dp"> <EditText android:id="@+id/password_ET" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toLeftOf="@+id/iv_psw_eye" android:background="@null" android:gravity="center_vertical" android:hint="請(qǐng)輸入密碼" android:inputType="textPassword" android:maxLines="1" android:textColor="@color/color_666666" android:textColorHint="@color/color_999999" android:textSize="13sp" /> <ImageView android:id="@+id/iv_psw_eye" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentRight="true" android:paddingLeft="20dp" android:paddingRight="26dp" android:src="@mipmap/icon_psw_eye" android:tag="1" /> </RelativeLayout>
截圖:
關(guān)于“Android開發(fā)EditText如何實(shí)現(xiàn)密碼顯示隱藏”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“Android開發(fā)EditText如何實(shí)現(xiàn)密碼顯示隱藏”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。