android - TextView with different colors -


i have problem code. trying make app checks if user writes sentence in right way. if doesn't, see words wrote wrong in red, otherwise see whole sentence in green.

check_b.setonclicklistener(new view.onclicklistener() {      @override     public void onclick(view v) {         final string[] dan_res = dan.split(" ");         string[] text_res = check_text.gettext().tostring().split(" ");          (int = 0; i<text_res.length; i++) {             if (text_res[i] != dan_res[i]) {                 spannablestring text = new spannablestring(text_res[i]);                   // make "lorem" (characters 0 5) red                   text.setspan(new foregroundcolorspan(color.red), 0, i, 0);                 dan_view.append(text_res[i]);             }             else {                 dan_view.settextcolor(color.green);             }         }     } }); 

perhaps easiest way use html:

textview.settext(html.fromhtml("<font color='red'>this red.</font><font color='green'>and green.</font>")); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -