国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

Android中EditText顯示明文與密碼的兩種方式

2019-12-12 05:46:31
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

效果圖如下所述:

布局

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context="liu.basedemo.MainActivity"><EditTextandroid:id="@+id/etUsername"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="20dp"android:hint="請(qǐng)輸入用戶名"android:textColor="#000000"android:textColorHint="#55000000"android:textSize="20sp"/><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center_vertical"><EditTextandroid:id="@+id/etPassword"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="20dp"android:hint="請(qǐng)輸入密碼"android:inputType="textPassword"android:textColor="#000000"android:textColorHint="#55000000"android:textSize="20sp"/><CheckBoxandroid:checked="false"android:id="@+id/cbDisplayPassword"android:layout_width="50dp"android:layout_height="50dp"android:layout_alignParentRight="true"android:layout_centerVertical="true"android:button="@drawable/selector_password"/></RelativeLayout></LinearLayout>selector<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@mipmap/cb_checked" android:state_checked="true"/><item android:drawable="@mipmap/cb_normaled" android:state_checked="false"/></selector>

EditText顯示明文與密碼的兩種方式如下所述:

第一種方式

private void initListener() {mCbDisplayPassword.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {Log.d(TAG, "onCheckedChanged: "+isChecked);if(isChecked){//選擇狀態(tài) 顯示明文--設(shè)置為可見的密碼mEtPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);}else {//默認(rèn)狀態(tài)顯示密碼--設(shè)置文本 要一起寫才能起作用 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORDmEtPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);}}});}

第二種方式

private void initListener() {mCbDisplayPassword.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {Log.d(TAG, "onCheckedChanged: "+isChecked);if(isChecked){//選擇狀態(tài) 顯示明文--設(shè)置為可見的密碼//mEtPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);/*** 第二種*/mEtPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());}else {//默認(rèn)狀態(tài)顯示密碼--設(shè)置文本 要一起寫才能起作用 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD//mEtPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);/*** 第二種*/mEtPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());}}});}

以上所述是小編給大家介紹的Android中EditText顯示明文與密碼的兩種方式,希望對(duì)大家有所幫助,如果大家想了解更多內(nèi)容敬請(qǐng)關(guān)注武林網(wǎng)!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 土默特左旗| 涞水县| 武威市| 南平市| 灵璧县| 泰和县| 邹城市| 信阳市| 临朐县| 竹山县| 南平市| 香港| 阜宁县| 外汇| 叶城县| 开远市| 兴安县| 司法| 江油市| 历史| 襄垣县| 平原县| 治县。| 曲水县| 蛟河市| 龙海市| 正安县| 白水县| 惠水县| 上栗县| 台北市| 龙州县| 临沂市| 泊头市| 江孜县| 大英县| 潢川县| 林西县| 柏乡县| 林西县| 柏乡县|