Android dynamically displays the content of the hidden password input box

Source: Internet
Author: User

Set the settransformationmethod () method of edittext to hide the password or display the password. For example:

Private button mbtnpassword; <br/> private edittext metpassword; <br/> private Boolean mbdisplayflg = false; </P> <p>/** called when the activity is first created. */<br/> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); </P> <p> metpassword = (edittext) findviewbyid (R. id. password); <br/> mbtnpassword = (butt On) findviewbyid (R. id. btnpassword); <br/> mbtnpassword. setonclicklistener (New onclicklistener () {</P> <p> @ override <br/> Public void onclick (view V) {<br/> // todo auto-generated method stub <br/> log. D ("androidtest", "mbdisplayflg =" + mbdisplayflg); <br/> If (! Mbdisplayflg) {<br/> // display Password text, for example "123456" <br/> metpassword. settransformationmethod (hidereturnstransformationmethod. getinstance (); <br/>}else {<br/> // hide password, display ". "<br/> metpassword. settransformationmethod (passwordtransformationmethod. getinstance (); <br/>}< br/> mbdisplayflg =! Mbdisplayflg; <br/> metpassword. postinvalidate (); <br/>}</P> <p >}); </P> <p>}

 

Main. xml

 

 <? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent"> <br/> <button Android: Id = "@ + ID/btnpassword" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: text = "password"/> <br/> <edittext Android: id = "@ + ID/password" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: password = "true" <br/> Android: textsize = "18sp" <br/> Android: TEXT = "123456"> <br/> </edittext> <br/> </linearlayout>

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.