日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Android實現密碼隱藏和顯示_Android

作者:Swift社區 ? 更新時間: 2022-09-27 編程語言

本文實例為大家分享了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

欄目分類
最近更新