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:

hint remaining digits

when user inputs digit, appears this:

hint remaining digits

(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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -