This article shows the Android implementation of dynamic display or hidden password input box content method, share for everyone to use for reference. The specific methods are as follows:
This feature enables you to either hide the password or display the password by setting the EditText Settransformationmethod () method.
The sample code is as follows:
private button Mbtnpassword, private EditText Metpassword, private Boolean MBDISPLAYFLG
= false; /** called the activity is a.
* * @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 (Hidereturnstra
Nsformationmethod.getinstance ());
else {//Hide password, display '. '
Metpassword.settransformationmethod (Passwordtransformationmethod.getinstance ());
} MBDISPLAYFLG =!MBDISPLAYFLG;
Metpassword.postinvalidate ();
}
}); }
Main.xml files are as follows:
<?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= "password"/>
<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>
I hope this article will help you with your Android program.