最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)EditText實(shí)現(xiàn)密碼顯示隱藏

 更新時(shí)間:2022年08月02日 11:34:24   作者:伊文他媽  
這篇文章主要為大家詳細(xì)介紹了Android開發(fā)EditText實(shí)現(xiàn)密碼顯示隱藏,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

最近在做一個(gè)登錄、注冊(cè)頁面,里面需要顯示或隱藏密碼,故做了一個(gè)簡單的顯示和隱藏功能。

關(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>

截圖:

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

三明市| 滦南县| 化州市| 大渡口区| 黄山市| 延庆县| 柘城县| 南皮县| 巴彦淖尔市| 海阳市| 马尔康县| 时尚| 巩义市| 山丹县| 家居| 武邑县| 光泽县| 灌南县| 枣阳市| 攀枝花市| 鄯善县| 南京市| 凤阳县| 廊坊市| 安西县| 辽中县| 本溪市| 南木林县| 绿春县| 桃源县| 三亚市| 兴义市| 南安市| 包头市| 巴马| 甘肃省| 宿州市| 吴旗县| 永嘉县| 错那县| 霸州市|