Android中實現(xiàn)密碼的隱藏和顯示的示例
更新時間:2017年09月13日 16:22:58 作者:L展菲Q
本篇文章主要介紹了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>
隱藏圖標(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());
}
}
});
}
}
效果展示:


以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Android實現(xiàn)密碼隱藏和顯示
- Android實現(xiàn)顯示和隱藏密碼功能的示例代碼
- Android 登錄頁面的實現(xiàn)代碼(密碼顯示隱藏、EditText 圖標(biāo)切換、限制輸入長度)
- 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中TabLayout結(jié)合ViewPager實現(xiàn)頁面切換效果
這篇文章主要介紹了Android中TabLayout結(jié)合ViewPager實現(xiàn)頁面切換效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-10-10
java從輸入流中獲取數(shù)據(jù)并返回字節(jié)數(shù)組示例
這篇文章主要介紹了java從輸入流中獲取數(shù)據(jù)并以字節(jié)數(shù)組返回,這是一個常用的方法,以后可以直接拿來用。這種輸入流可以來自Android本地,也可以來自網(wǎng)絡(luò)2014-01-01
Android實現(xiàn)長按back鍵退出應(yīng)用程序的方法
這篇文章主要介紹了Android實現(xiàn)長按back鍵退出應(yīng)用程序的方法,實例分析了Android按鈕事件的操作技巧,需要的朋友可以參考下2015-05-05

