Android實(shí)現(xiàn)動態(tài)顯示或隱藏密碼輸入框的內(nèi)容
本文實(shí)例展示了Android實(shí)現(xiàn)動態(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>
希望本文所述對大家的Android程序設(shè)計(jì)有所幫助。
- Android實(shí)現(xiàn)密碼隱藏和顯示
- Android實(shí)現(xiàn)顯示和隱藏密碼功能的示例代碼
- Android 登錄頁面的實(shí)現(xiàn)代碼(密碼顯示隱藏、EditText 圖標(biāo)切換、限制輸入長度)
- Android中實(shí)現(xiàn)密碼的隱藏和顯示的示例
- Android EditText密碼的隱藏和顯示功能
- Android 密碼 顯示與隱藏功能實(shí)例
- Android中實(shí)現(xiàn)EditText密碼顯示隱藏的方法
- Android文本輸入框(EditText)輸入密碼時顯示與隱藏
- Android中EditText顯示明文與密碼的兩種方式
- Android開發(fā)EditText實(shí)現(xiàn)密碼顯示隱藏
相關(guān)文章
自定義RadioButton和ViewPager實(shí)現(xiàn)TabHost帶滑動的頁卡效果
在工作中又很多需求都不是android系統(tǒng)自帶的控件可以達(dá)到效果的所以這個時候就要自定義控件來達(dá)到效果:使用自定義RadioButton和ViewPager實(shí)現(xiàn)TabHost帶滑動的頁卡效果2013-01-01Android開發(fā)手機(jī)無線調(diào)試的方法
今天小編就為大家分享一篇關(guān)于Android開發(fā)手機(jī)無線調(diào)試的方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-12-12關(guān)于Android實(shí)現(xiàn)簡單的微信朋友圈分享功能
這篇文章主要介紹了關(guān)于Android實(shí)現(xiàn)簡單的微信朋友圈分享功能,非常不錯,具有參考借鑒價值,需要的的朋友參考下2017-02-02Kotlin封裝RecyclerView Adapter實(shí)例教程
這篇文章主要給大家介紹了關(guān)于Kotlin封裝RecyclerView Adapter的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08詳解Android JetPack之LiveData的工作原理
這篇文章主要介紹了詳解Android JetPack之LiveData的工作原理,幫助大家更好的理解和學(xué)習(xí)使用Android開發(fā),感興趣的朋友可以了解下2021-03-03