Android中實現(xiàn)密碼的隱藏和顯示的示例
在Android開發(fā)中,需要密碼的隱藏和顯示,下面就和大家分享一下使用方法:
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="請設(shè)置登錄密碼" 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()); } } }); } }
效果展示:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android實現(xiàn)密碼隱藏和顯示
- Android實現(xiàn)顯示和隱藏密碼功能的示例代碼
- Android 登錄頁面的實現(xiàn)代碼(密碼顯示隱藏、EditText 圖標切換、限制輸入長度)
- Android EditText密碼的隱藏和顯示功能
- Android 密碼 顯示與隱藏功能實例
- Android中實現(xiàn)EditText密碼顯示隱藏的方法
- Android文本輸入框(EditText)輸入密碼時顯示與隱藏
- Android實現(xiàn)動態(tài)顯示或隱藏密碼輸入框的內(nèi)容
- Android中EditText顯示明文與密碼的兩種方式
- Android開發(fā)EditText實現(xiàn)密碼顯示隱藏
相關(guān)文章
android計算器實現(xiàn)兩位數(shù)的加減乘除
這篇文章主要為大家詳細介紹了android計算器實現(xiàn)兩位數(shù)的加減乘除,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-03-03Android實現(xiàn)基于ViewPager的無限循環(huán)自動播放帶指示器的輪播圖CarouselFigureView控件
這篇文章主要介紹了Android實現(xiàn)基于ViewPager的無限循環(huán)自動播放帶指示器的輪播圖CarouselFigureView控件,需要的朋友可以參考下2017-02-02Android TextWatcher三個回調(diào)以及監(jiān)聽EditText的輸入案例詳解
這篇文章主要介紹了Android TextWatcher三個回調(diào)以及監(jiān)聽EditText的輸入案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-08-08Android開發(fā)之搜索框SearchView用法示例
這篇文章主要介紹了Android開發(fā)之搜索框SearchView用法,結(jié)合實例形式分析了Android搜索框SearchView的基本功能、用法及相關(guān)操作注意事項,需要的朋友可以參考下2019-03-03Android學(xué)習(xí)教程之分類側(cè)滑菜單(5)
這篇文章主要為大家詳細介紹了Android學(xué)習(xí)教程之分類側(cè)滑菜單的具體代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11Android實現(xiàn)二維碼掃描并登陸網(wǎng)頁
這篇文章主要介紹了Android實現(xiàn)二維碼掃描并登陸網(wǎng)頁的相關(guān)資料,需要的朋友可以參考下2016-05-05Android實現(xiàn)志愿者系統(tǒng)詳細步驟與代碼
這篇文章主要介紹了Android實現(xiàn)志愿者系統(tǒng),本系統(tǒng)采用MVC架構(gòu)設(shè)計,SQLite數(shù)據(jù)表有用戶表、成員表和活動表,有十多個Activity頁面。打開應(yīng)用,進入歡迎界面,3s后跳轉(zhuǎn)登錄界面,用戶先注冊賬號,登錄成功后進入主界面2023-02-02