Android實現(xiàn)動態(tài)顯示或隱藏密碼輸入框的內(nèi)容
更新時間:2014年09月04日 11:35:01 投稿:shichen2014
這篇文章主要介紹了Android實現(xiàn)動態(tài)顯示或隱藏密碼輸入框的內(nèi)容,主要通過設(shè)置EditText的setTransformationMethod()方法來實現(xiàn),需要的朋友可以參考下
本文實例展示了Android實現(xiàn)動態(tài)顯示或隱藏密碼輸入框內(nèi)容的方法,分享給大家供大家參考之用。具體方法如下:
該功能可通過設(shè)置EditText的setTransformationMethod()方法來實現(xiàn)隱藏密碼或者顯示密碼。
示例代碼如下:
private Button mBtnPassword;
private EditText mEtPassword;
private boolean mbDisplayFlg = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mEtPassword = (EditText)findViewById(R.id.password);
mBtnPassword = (Button)findViewById(R.id.btnPassword);
mBtnPassword.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("AndroidTest", "mbDisplayFlg = " + mbDisplayFlg);
if (!mbDisplayFlg) {
// display password text, for example "123456"
mEtPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
} else {
// hide password, display "."
mEtPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
mbDisplayFlg = !mbDisplayFlg;
mEtPassword.postInvalidate();
}
});
}
main.xml文件如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/btnPassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密碼" /> <EditText android:id="@+id/password" android:layout_width="fill_parent" android:layout_height="wrap_content" android:password="true" android:textSize="18sp" android:text="123456"> </EditText> </LinearLayout>
希望本文所述對大家的Android程序設(shè)計有所幫助。
您可能感興趣的文章:
- Android實現(xiàn)密碼隱藏和顯示
- Android實現(xiàn)顯示和隱藏密碼功能的示例代碼
- Android 登錄頁面的實現(xiàn)代碼(密碼顯示隱藏、EditText 圖標(biāo)切換、限制輸入長度)
- Android中實現(xiàn)密碼的隱藏和顯示的示例
- Android EditText密碼的隱藏和顯示功能
- Android 密碼 顯示與隱藏功能實例
- Android中實現(xiàn)EditText密碼顯示隱藏的方法
- Android文本輸入框(EditText)輸入密碼時顯示與隱藏
- Android中EditText顯示明文與密碼的兩種方式
- Android開發(fā)EditText實現(xiàn)密碼顯示隱藏
相關(guān)文章
Android動態(tài)使用VectorDrawable過程詳解
這篇文章主要介紹了Android動態(tài)使用VectorDrawable過程,2014年6月26日的I/O 2014開發(fā)者大會上谷歌正式推出了Android L,它帶來了全新的設(shè)計語言Material Design,新的API也提供了這個類VectorDrawable2023-02-02
Android ApplicationContext接口深入分析
ApplicationContext是Spring應(yīng)用程序中的中央接口,由于繼承了多個組件,使得ApplicationContext擁有了許多Spring的核心功能,如獲取bean組件,注冊監(jiān)聽事件,加載資源文件等2022-11-11
Android對EditTex的圖片實現(xiàn)監(jiān)聽
這篇文章主要為大家詳細(xì)介紹了Android如何對EditTex的圖片實現(xiàn)監(jiān)聽,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-10-10
Android實現(xiàn)自定義的衛(wèi)星式菜單(弧形菜單)詳解
相信大家經(jīng)常在應(yīng)用中會看到衛(wèi)星菜單,那么這篇文章就來介紹在Android中如何實現(xiàn)自定義的衛(wèi)星式菜單(弧形菜單),有需要的可以參考學(xué)習(xí)。2016-08-08

