網站首頁 編程語言 正文
本文實例為大家分享了Android實現密碼隱藏和顯示的具體代碼,供大家參考,具體內容如下
在Android開發中,需要密碼的隱藏和顯示,下面就和大家分享一下使用方法:
xml代碼:
<LinearLayout? ? ? ? ? ? ? android:layout_width="match_parent" ? ? ? ? ? ? android:layout_height="50dp" ? ? ? ? ? ? android:background="@color/white" ? ? ? ? ? ? android:orientation="horizontal" > ? ? ? ? ? ? <TextView ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="match_parent" ? ? ? ? ? ? ? ? android:text="新密碼" ? ? ? ? ? ? ? ? android:textColor="@color/black" ? ? ? ? ? ? ? ? android:textSize="18dp" ? ? ? ? ? ? ? ? android:gravity="center_vertical" ? ? ? ? ? ? ? ? android:layout_marginLeft="15dp"/> ? ? ? ? ? ? <EditText ? ? ? ? ? ? ? ? android:id="@+id/newpassword" ? ? ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? ? ? android:layout_weight="1" ? ? ? ? ? ? ? ? android:layout_height="match_parent" ? ? ? ? ? ? ? ? android:layout_gravity="center_vertical" ? ? ? ? ? ? ? ? android:layout_marginLeft="10dp" ? ? ? ? ? ? ? ? android:inputType="textPassword" ? ? ? ? ? ? ? ? android:hint="請設置登錄密碼" ? ? ? ? ? ? ? ? android:background="@null"/> ? ? ? ? ? ? <CheckBox ? ? ? ? ? ? ? ? android:id="@+id/CheckBox" ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="match_parent" ? ? ? ? ? ? ? ? android:layout_marginRight="15dp" ? ? ? ? ? ? ? ? android:textSize="16dp" ? ? ? ? ? ? ? ? android:text="顯示" ? ? ? ? ? ? ? ? /> </LinearLayout>
####隱藏圖標代碼
android:button="@null"
JAVA代碼:
/**
?* Created by fby on 2017/9/11.
?*/
public class ChargepsdActivity extends Activity {
? ? private EditText editText;
? ? private CheckBox checkBox;
? ? @Override
? ? protected void onCreate(@Nullable Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_chargepsd);
? ? ? ? editText = (EditText) findViewById(R.id.newpassword);
? ? ? ? checkBox = (CheckBox) findViewById(R.id.CheckBox);
? ? ? ? checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
? ? ? ? ? ? ? ? if(isChecked){
? ? ? ? ? ? ? ? ? ? //如果選中,顯示密碼
? ? ? ? ? ? ? ? ? ? editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? //否則隱藏密碼
? ? ? ? ? ? ? ? ? ? editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? }
}
效果展示:
Android開發~獲取驗證碼倒計時實現
原文鏈接:https://blog.csdn.net/qq_36478920/article/details/89456419
相關推薦
- 2022-12-09 C++?如何將string轉換成全小寫_C 語言
- 2022-10-05 Python線程池的實現淺析_python
- 2023-07-15 css 多余部分用省略號代替
- 2022-07-23 Python實現環形鏈表_python
- 2022-06-16 ASP.NET?Core?6.0?添加?JWT?認證和授權功能_實用技巧
- 2023-02-10 批處理從html格式(接收到的郵件)中讀取數據的操作方法_DOS/BAT
- 2022-04-20 在Python反編譯中批量pyc轉?py的實現代碼_python
- 2022-06-25 python多進程和多線程介紹_python
- 最近更新
-
- 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同步修改后的遠程分支