Android SetColorFilter() vs. SetBackgroundResource() / SetColorBackground() -
can explain difference in appearance? setcolorfilter() acts on background drawable, whether setbackgroundresource() sets background color. in android version 2.3 safely used setcolorfilter() alter background color of edittext, since easy restore original color clearing filter. no need , remember it. there seems difference between 2 ways.
this edittextpreference dialog box, et edittext id.
public void aftertextchanged(editable s) { string source = s.tostring(); et.removetextchangedlistener(this); if( !source.matches("^[0-9]+$") ) { et.getbackground().setcolorfilter(getresources().getcolor(r.color.invalid), mode.overlay); et.invalidate(); et.selectall(); } else { et.getbackground().clearcolorfilter(); et.invalidate(); } et.addtextchangedlistener(this); }
and same code using setbackgroundresource()
public void aftertextchanged(editable s) { string source = s.tostring(); et.removetextchangedlistener(this); if( !source.matches("^[0-9]+$") ) { et.setbackgroundresource(r.color.invalid); et.selectall(); } else { et.setbackgroundresource(r.color.valid); } et.addtextchangedlistener(this); }
you can utilize textview.seterror("error message")
mentioned above. if want customize behavior of seterror() (such changing background color), sadly plenty need override edittext , write own handler seterror, shown here: edittext seterror() icon without popup message
android android-edittext background-color
No comments:
Post a Comment