android - Two drawable to edittext -


i have added drawables both ends of edittext. when click on right drawable, left 1 disappears. edittext password input.icon lock , icon visibility(eye) left , right of edittext respectivily.the right icon toggles per visibility of password

listener implementation right drawable:

 etpassword.setontouchlistener(new view.ontouchlistener() {             @override             public boolean ontouch(view v, motionevent event) {                 final int drawable_right = 2;                  if (event.getaction() == motionevent.action_down) {                     if (event.getrawx() >= (etpassword.getright() - etpassword.getcompounddrawables()[drawable_right].getbounds().width())) {                         if (etpassword.getinputtype() == inputtype.type_text_variation_visible_password) {                             etpassword.setinputtype(inputtype.type_class_text |                                     inputtype.type_text_variation_password);                             etpassword.setcompounddrawableswithintrinsicbounds(0, 0, r.drawable.ic_visibility_off_white_24dp, 0);                             etpassword.setselection(etpassword.gettext().length());                         } else {                             etpassword.setinputtype(inputtype.type_text_variation_visible_password);                             etpassword.setcompounddrawableswithintrinsicbounds(0, 0, r.drawable.ic_visibility_white_24dp, 0);                          }                         return true;                     }                 }                 return false;             }         }); 

xml:

 <edittext                 android:id="@+id/etpassword"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_margintop="5dp"                 android:background="@drawable/et_bg"                 android:drawableright="@drawable/ic_visibility_off_white_24dp"                 android:hint="@string/password"                 android:drawableleft="@drawable/ic_lock_white_24dp"                 android:inputtype="textpassword"                 android:maxlines="1"                 android:padding="10dp"                 android:singleline="true"                 android:textappearance="?android:attr/textappearancemedium"                 android:textcolor="@color/textcolorprimary" /> 

screen shots: enter image description here

the issue on clicking visibility icon, left drawable disappears,here's screenshot enter image description here

you adding 0 start|left icon position of edittext etpassword.setcompounddrawableswithintrinsicbounds(0, 0, r.drawable.ic_visibility_off_white_24dp, 0);

add lock_icon in start|left position of edittext :

etpassword.setcompounddrawableswithintrinsicbounds(lock_icon, 0, r.drawable.ic_visibility_off_white_24dp, 0); 

final code:

etpassword.setontouchlistener(new view.ontouchlistener() {             @override             public boolean ontouch(view v, motionevent event) {                 final int drawable_right = 2;                  if (event.getaction() == motionevent.action_down) {                     if (event.getrawx() >= (etpassword.getright() - etpassword.getcompounddrawables()[drawable_right].getbounds().width())) {                         if (etpassword.getinputtype() == inputtype.type_text_variation_visible_password) {                             etpassword.setinputtype(inputtype.type_class_text |                                     inputtype.type_text_variation_password);                             etpassword.setcompounddrawableswithintrinsicbounds(lock_icon, 0, r.drawable.ic_visibility_off_white_24dp, 0);                             etpassword.setselection(etpassword.gettext().length());                         } else {                             etpassword.setinputtype(inputtype.type_text_variation_visible_password);                             etpassword.setcompounddrawableswithintrinsicbounds(lock_icon, 0, r.drawable.ic_visibility_white_24dp, 0);                          }                         return true;                     }                 }                 return false;             }         }); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -