Android實(shí)現(xiàn)動(dòng)態(tài)顯示或隱藏密碼輸入框的內(nèi)容
本文實(shí)例展示了Android實(shí)現(xiàn)動(dòng)態(tài)顯示或隱藏密碼輸入框內(nèi)容的方法,分享給大家供大家參考之用。具體方法如下:
該功能可通過設(shè)置EditText的setTransformationMethod()方法來(lái)實(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 登錄頁(yè)面的實(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 View移動(dòng)的3種方式總結(jié)
這篇文章主要給大家介紹了Android View移動(dòng)的三種方式,在介紹這三種方式之前先介紹了Android坐標(biāo)系的定義規(guī)則以及View的一些位置參數(shù)。有需要的朋友們可以參考借鑒。2016-09-09Android Dialog對(duì)話框用法實(shí)例詳解
這篇文章主要介紹了Android Dialog對(duì)話框用法,結(jié)合實(shí)例形式分析了Android使用Dialog對(duì)話框過程中所涉及的創(chuàng)建、保存、回復(fù)等操作相關(guān)技巧與注意事項(xiàng),需要的朋友可以參考下2016-07-07自定義RadioButton和ViewPager實(shí)現(xiàn)TabHost帶滑動(dòng)的頁(yè)卡效果
在工作中又很多需求都不是android系統(tǒng)自帶的控件可以達(dá)到效果的所以這個(gè)時(shí)候就要自定義控件來(lái)達(dá)到效果:使用自定義RadioButton和ViewPager實(shí)現(xiàn)TabHost帶滑動(dòng)的頁(yè)卡效果2013-01-01Android開發(fā)手機(jī)無(wú)線調(diào)試的方法
今天小編就為大家分享一篇關(guān)于Android開發(fā)手機(jī)無(wú)線調(diào)試的方法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-12-12關(guān)于Android實(shí)現(xiàn)簡(jiǎn)單的微信朋友圈分享功能
這篇文章主要介紹了關(guān)于Android實(shí)現(xiàn)簡(jiǎn)單的微信朋友圈分享功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下2017-02-02Kotlin封裝RecyclerView Adapter實(shí)例教程
這篇文章主要給大家介紹了關(guān)于Kotlin封裝RecyclerView Adapter的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08詳解Android JetPack之LiveData的工作原理
這篇文章主要介紹了詳解Android JetPack之LiveData的工作原理,幫助大家更好的理解和學(xué)習(xí)使用Android開發(fā),感興趣的朋友可以了解下2021-03-03