Android implement dynamic Display or hide the contents of the Password input box _android

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.