Android實現(xiàn)密碼隱藏和顯示
本文實例為大家分享了Android實現(xiàn)密碼隱藏和顯示的具體代碼,供大家參考,具體內(nèi)容如下
在Android開發(fā)中,需要密碼的隱藏和顯示,下面就和大家分享一下使用方法:
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="請設(shè)置登錄密碼" ? ? ? ? ? ? ? ? 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開發(fā)~獲取驗證碼倒計時實現(xiàn)
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android實現(xiàn)顯示和隱藏密碼功能的示例代碼
- Android 登錄頁面的實現(xiàn)代碼(密碼顯示隱藏、EditText 圖標切換、限制輸入長度)
- Android中實現(xiàn)密碼的隱藏和顯示的示例
- Android EditText密碼的隱藏和顯示功能
- Android 密碼 顯示與隱藏功能實例
- Android中實現(xiàn)EditText密碼顯示隱藏的方法
- Android文本輸入框(EditText)輸入密碼時顯示與隱藏
- Android實現(xiàn)動態(tài)顯示或隱藏密碼輸入框的內(nèi)容
- Android中EditText顯示明文與密碼的兩種方式
- Android開發(fā)EditText實現(xiàn)密碼顯示隱藏
相關(guān)文章
Android Jetpack組件中LiveData的優(yōu)劣
LiveData是Jetpack組件的一部分,更多的時候是搭配ViewModel來使用,相對于Observable,LiveData的最大優(yōu)勢是其具有生命感知的,換句話說,LiveData可以保證只有在組件(?Activity、Fragment、Service)處于活動生命周期狀態(tài)的時候才會更新數(shù)據(jù)2023-04-04
Android9.0 SystemUI 網(wǎng)絡(luò)信號欄定制修改的流程解析
這篇文章主要介紹了Android9.0 SystemUI 網(wǎng)絡(luò)信號欄定制修改的流程,本文通過圖文實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-11-11
Android 滑動監(jiān)聽RecyclerView線性流+左右劃刪除+上下移動
這篇文章主要介紹了Android 滑動監(jiān)聽RecyclerView線性流+左右劃刪除+上下移動的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-09-09
android開發(fā)教程之實現(xiàn)listview下拉刷新和上拉刷新效果
這篇文章主要介紹了android實現(xiàn)listview下拉刷新和上拉刷新效果,Android的ListView上拉下拉刷新,原理都一樣,在Touch事件中操作header/footer的paddingTop屬性,需要的朋友可以參考下2014-02-02
Compose狀態(tài)保存rememberSaveable原理解析
這篇文章主要為大家介紹了Compose狀態(tài)保存rememberSaveable原理解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11

