Placeholder hint while typing in EditText in Android -
i have edittext field , user may input 6 digits. when edittext focused, should hint user can input 6 digits.
the idea display remaining digits in gray, this:
when user inputs digit, appears this:
(the red vertical bar represents cursor.)
the cursor should not positioned behind current position in both images; gray digits should visible, , should not selectable.
so in fact want set placeholder text, retain part of placeholder text whilst user typing.
i read textinputlayout class design support library, don't know how can achieve abovementioned idea.
how this?
i give idea, implementation you. create textwatcher, in
ontextchanged() count how many digits user wrote , depending on number create string padded zeros. after it, make zeros of different color
spannable textwithtintedzeros = new spannablestring(paddedstring); textwithtintedzeros.setspan(new foregroundcolorspan(yourgrey), firstzeroindex, length, spannable.span_inclusive_exclusive); edittext.settext(textwithtintedzeros); and @ last set selection before zeros with
edittext.setselection(indexbeforefirstzero); don't forget block changing cursor position. think can done with
view.onkeylistener 

Comments
Post a Comment