Android實(shí)現(xiàn)密碼隱藏和顯示
本文實(shí)例為大家分享了Android實(shí)現(xiàn)密碼隱藏和顯示的具體代碼,供大家參考,具體內(nèi)容如下
在Android開(kāi)發(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="請(qǐng)?jiān)O(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>
####隱藏圖標(biāo)代碼
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()); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? }); ? ? } }
效果展示:
Android開(kāi)發(fā)~獲取驗(yàn)證碼倒計(jì)時(shí)實(shí)現(xiàn)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 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實(shí)現(xiàn)動(dòng)態(tài)顯示或隱藏密碼輸入框的內(nèi)容
- Android中EditText顯示明文與密碼的兩種方式
- Android開(kāi)發(fā)EditText實(shí)現(xiàn)密碼顯示隱藏
相關(guān)文章
Android中AutoCompleteTextView與TextWatcher結(jié)合小實(shí)例
這篇文章主要為大家詳細(xì)介紹了Android中AutoCompleteTextView與TextWatcher結(jié)合的小實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05Android實(shí)現(xiàn)的RecyclerView適配器
這篇文章主要介紹了Android實(shí)現(xiàn)的RecyclerView適配器的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下2021-03-03Android帶刷新時(shí)間顯示的PullToRefresh上下拉刷新
這篇文章主要為大家詳細(xì)介紹了Android帶刷新時(shí)間顯示的PullToRefresh上下拉刷新,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12Android HorizontalScrollView內(nèi)子控件橫向拖拽實(shí)例代碼
本文主要介紹Android HorizontalScrollView的使用,這里給大家一個(gè)實(shí)例來(lái)展示HorizontalScrollView內(nèi)子控件橫向拖拽的效果實(shí)現(xiàn),有需要的小伙伴可以參考下2016-07-07解決java.lang.NoClassDefFoundError: android.support.v4.animati
這篇文章主要介紹了解決Android Studio出現(xiàn)java.lang.NoClassDefFoundError: android.support.v4.animation.AnimatorCompatHelper的問(wèn)題,感興趣的朋友一起看看吧2021-08-08Android打造流暢九宮格抽獎(jiǎng)活動(dòng)效果
抽獎(jiǎng)活動(dòng)有很多種形式,轉(zhuǎn)盤(pán)抽獎(jiǎng),九宮格抽獎(jiǎng),刮刮卡抽獎(jiǎng),這篇文章主要為大家詳細(xì)介紹了如何打造流暢九宮格抽獎(jiǎng)活動(dòng)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11Android編程基于Contacts讀取聯(lián)系人的方法(附demo源碼)
這篇文章主要介紹了Android編程基于Contacts讀取聯(lián)系人的方法,實(shí)例分析了Contacts讀取的實(shí)現(xiàn)方法及權(quán)限設(shè)置方法,并附帶了完整實(shí)例供讀者下載參考,需要的朋友可以參考下2015-12-12Android實(shí)現(xiàn)App中導(dǎo)航Tab欄懸浮的功能
相信大家在玩手機(jī)的過(guò)程中應(yīng)該會(huì)注意到很多的app都有這種功能,比如說(shuō)外賣(mài)達(dá)人常用的“餓了么”。所以這篇文章給大家分享了Android如何實(shí)現(xiàn)app中的導(dǎo)航Tab欄懸浮的功能,有需要的朋友們可以參考借鑒。2016-10-10