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

首頁 > 系統 > Android > 正文

Android中實現密碼的隱藏和顯示的示例

2019-10-22 18:27:51
字體:
來源:轉載
供稿:網友

在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,密碼顯示隱藏,密碼隱藏和顯示

android,密碼顯示隱藏,密碼隱藏和顯示

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长岭县| 黄山市| 横峰县| 易门县| 三河市| 漳浦县| 高邑县| 平昌县| 东山县| 郁南县| 正安县| 宁德市| 沁阳市| 茌平县| 栖霞市| 泰安市| 巴彦淖尔市| 昌江| 内丘县| 深泽县| 泸定县| 清新县| 新泰市| 阿克| 漠河县| 博白县| 大理市| 宕昌县| 白河县| 福清市| 英超| 蓝田县| 潼关县| 泗阳县| 通榆县| 舟曲县| 舒兰市| 雷山县| 石台县| 清镇市| 宁城县|