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