Android實(shí)現(xiàn)動(dòng)態(tài)顯示或隱藏密碼輸入框的內(nèi)容
本文實(shí)例展示了Android實(shí)現(xiàn)動(dòng)態(tài)顯示或隱藏密碼輸入框內(nèi)容的方法,分享給大家供大家參考之用。具體方法如下:
該功能可通過設(shè)置EditText的setTransformationMethod()方法來實(shí)現(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>
希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。
- Android實(shí)現(xiàn)密碼隱藏和顯示
- Android實(shí)現(xiàn)顯示和隱藏密碼功能的示例代碼
- Android 登錄頁面的實(shí)現(xiàn)代碼(密碼顯示隱藏、EditText 圖標(biāo)切換、限制輸入長(zhǎng)度)
- Android中實(shí)現(xiàn)密碼的隱藏和顯示的示例
- Android EditText密碼的隱藏和顯示功能
- Android 密碼 顯示與隱藏功能實(shí)例
- Android中實(shí)現(xiàn)EditText密碼顯示隱藏的方法
- Android文本輸入框(EditText)輸入密碼時(shí)顯示與隱藏
- Android中EditText顯示明文與密碼的兩種方式
- Android開發(fā)EditText實(shí)現(xiàn)密碼顯示隱藏
相關(guān)文章
Android動(dòng)態(tài)使用VectorDrawable過程詳解
這篇文章主要介紹了Android動(dòng)態(tài)使用VectorDrawable過程,2014年6月26日的I/O 2014開發(fā)者大會(huì)上谷歌正式推出了Android L,它帶來了全新的設(shè)計(jì)語言Material Design,新的API也提供了這個(gè)類VectorDrawable2023-02-02
Android編程實(shí)現(xiàn)帶漸變效果的圓角矩形示例
這篇文章主要介紹了Android編程實(shí)現(xiàn)帶漸變效果的圓角矩形,涉及Android界面布局及屬性設(shè)置相關(guān)操作技巧,需要的朋友可以參考下2017-08-08
Android ApplicationContext接口深入分析
ApplicationContext是Spring應(yīng)用程序中的中央接口,由于繼承了多個(gè)組件,使得ApplicationContext擁有了許多Spring的核心功能,如獲取bean組件,注冊(cè)監(jiān)聽事件,加載資源文件等2022-11-11
Android對(duì)EditTex的圖片實(shí)現(xiàn)監(jiān)聽
這篇文章主要為大家詳細(xì)介紹了Android如何對(duì)EditTex的圖片實(shí)現(xiàn)監(jiān)聽,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10
配置一個(gè)好用的Android模擬器讓你不再對(duì)模擬器那么失望
默認(rèn)情況下的Android模擬器窗口占據(jù)了屏幕巨大的空間,而且毫無緣由的放著一個(gè)屏幕鍵盤,如果你沒親自用過模擬器的話,還有一個(gè)不易發(fā)現(xiàn)的問題:幾乎是慢到不能用2013-01-01
Android實(shí)現(xiàn)單選與多選對(duì)話框的代碼
這篇文章主要介紹了Android實(shí)現(xiàn)單選與多選對(duì)話框的代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-01-01
Android實(shí)現(xiàn)自定義的衛(wèi)星式菜單(弧形菜單)詳解
相信大家經(jīng)常在應(yīng)用中會(huì)看到衛(wèi)星菜單,那么這篇文章就來介紹在Android中如何實(shí)現(xiàn)自定義的衛(wèi)星式菜單(弧形菜單),有需要的可以參考學(xué)習(xí)。2016-08-08
Android實(shí)現(xiàn)圖片設(shè)置圓角形式
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)圖片設(shè)置圓角形式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11

