Password Clear Text redaction switch

Source: Internet
Author: User

Demand:

Once the input box has a value, the delete icon is displayed; Click the toggle button, you can toggle

Layout:

<relativelayout android:layout_width= "Match_parent"Android:layout_height= "? attr/actionbarsize" > <EditText Android:id= "@+id/login_pwd"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:hint= "Please enter password"Android:paddingleft= "50DP"Android:paddingright= "100DP"Android:singleline= "true"Android:password= "true"/> <ImageView android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centervertical= "true"Android:layout_marginleft= "10DP"android:padding= "5DP"android:src= "@drawable/iconfont_pwd"/> <ImageView Android:id= "@+id/login_change"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentright= "true"android:layout_centervertical= "true"Android:layout_marginright= "10DP"Android:background= "@drawable/display"/> <ImageView Android:id= "@+id/login_change2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentright= "true"android:layout_centervertical= "true"Android:layout_marginright= "10DP"Android:background= "@drawable/display_text"android:visibility= "Gone"/> <ImageView Android:id= "@+id/login_pwd_clean"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centervertical= "true"Android:layout_alignparentright= "true"Android:layout_marginright= "70DP"android:src= "@drawable/search_clear_normal"android:visibility= "Invisible"/></relativelayout>

Code

//Listen for password inputLogin_pwd.addtextchangedlistener (NewTextwatcher () {PrivateCharsequence temp; @Override Public voidBeforetextchanged (Charsequence S,intStartintCountintAfter ) {Temp=s; } @Override Public voidOnTextChanged (Charsequence S,intStartintBefore,intcount) {} @Override Public voidaftertextchanged (Editable s) {if(Temp.length () > 0) {//Limit Lengthlogin_pwd_clean.setvisibility (view.visible); } Else{login_pwd_clean.setvisibility (view.invisible); }    }});
Login_pwd_clean.setonclicklistener (new  View.onclicklistener () {            @Override            public  void  OnClick (View v) {                login_pwd.settext ("");                Login_pwd_clean.setvisibility (view.invisible);            }        });
//Password Displays clear textLogin_change.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {loginactivity. This. Login_pwd.settransformationmethod (Hidereturnstransformationmethod.getinstance ());        Login_change.setvisibility (View.gone);    Login_change2.setvisibility (view.visible); }});//Password Display ciphertextLogin_change2.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {loginactivity. This. Login_pwd.settransformationmethod (Passwordtransformationmethod.getinstance ());        Login_change2.setvisibility (View.gone);    Login_change.setvisibility (view.visible); }});

Password Clear Text redaction switch

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.