網站首頁 編程語言 正文
最近在做一個登錄、注冊頁面,里面需要顯示或隱藏密碼,故做了一個簡單的顯示和隱藏功能。
關鍵類TextView.setTransformationMethod(TransformationMethod method),其中TransformationMethod 有兩個子類:
- HideReturnsTransformationMethod 隱藏回車
- PasswordTransformationMethod 密碼類型
關鍵代碼:
@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屬性存儲當前密碼輸入框的類型,1是密碼類型,2是顯示類型。布局組件關鍵代碼如下:
<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="請輸入密碼" ? ? ? ? ? ? ? ? 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>
截圖:
原文鏈接:https://blog.csdn.net/xll712/article/details/120885723
相關推薦
- 2022-06-07 Python?Numpy庫的超詳細教程_python
- 2021-11-21 關于.NET6?Minimal?API的使用方式詳解_實用技巧
- 2022-06-25 C++虛函數表的原理與使用解析_C 語言
- 2023-04-24 詳解python?__init__.py?和?__all__作用_python
- 2023-06-04 Flask框架中的session設置詳解_python
- 2022-03-12 c++調用實現yolov5轉onnx介紹_C 語言
- 2022-06-27 Golang編程并發工具庫MapReduce使用實踐_Golang
- 2022-12-24 Kubernetes?kubectl中Pod創建流程源碼解析_云和虛擬化
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支