android - How to use custom image for edittext password like axis bank app -
how use custom image instead of '*' in edittext password field?
see image:
any answer or hint appreciated.
the answer comes this tutorial , covers behaviour when user:
enters login screen, keyboard open automatically.
tries enter value in textbox background changes textbox star background.
tries cancel/delete input value using key on keyboard textbox background change textbox without star background.
first of have create 2 drawables
:
then, according approach, have implement addtextchangedlistener
method on edittext
. after that, parameter, create new instance of textwatcher
class , implement methods:
etxtpin1.addtextchangedlistener(new textwatcher() { @override public void ontextchanged(charsequence s, int start, int before, int count) { // todo auto-generated method stub } @override public void beforetextchanged(charsequence s, int start, int count, int after) { // todo auto-generated method stub } @override public void aftertextchanged(editable s) { if(etxtpin1.gettext().tostring().trim().length()==1){ etxtpin1.clearfocus(); etxtpin2.requestfocus(); etxtpin1.setbackgroundresource(r.drawable.pin_txt_bg_star); } } });
then, have implement setonkeylistener
, method onkey
:
this.etxtpin1.setonkeylistener(new view.onkeylistener() { public boolean onkey(view paramview, int paramint, keyevent paramkeyevent) { if ((paramkeyevent.getaction() == keyevent.action_down)&&(paramint == 67) && (loginactivity.this.etxtpin2.gettext().length() == 0)) { etxtpin1.requestfocus(); etxtpin1.setbackgroundresource(r.drawable.pin_txt_bg); etxtpin1.settext(""); } return false; } });
another approach: create own class extends passwordtransformationmethod.
public class mypasswordtransformationmethod extends passwordtransformationmethod { @override public charsequence gettransformation(charsequence source, view view) { return new passwordcharsequence(source); } private class passwordcharsequence implements charsequence { private charsequence msource; public passwordcharsequence(charsequence source) { msource = source; // store char sequence } public char charat(int index) { return '*'; // important part } public int length() { return msource.length(); // return default } public charsequence subsequence(int start, int end) { return msource.subsequence(start, end); // return default } } };
reference: in android how show asterisk (*) in place of dots in edittext having inputtype textpassword?
Comments
Post a Comment