android - highlight text inside a textview -


i have textview random background color (could color really). have text on textview need readable. assume best solution highlight said text in white , set text color black.

my question is: possible highlight text inside texview xml?

i have following in layout:

  <textview         android:layout_width="100dp"         android:layout_height="100dp"         android:id="@+id/colorbutton4"         android:layout_gravity="right|bottom"         android:background="@drawable/layout_border"         android:layout_marginright="30dp"         android:layout_marginbottom ="30dp"         android:clickable="true"         android:onclick="onclick"         android:gravity="center"         android:textcolorhighlight="@color/bgwhite"         android:textcolor="@color/black"         android:text="5431354" /> 

but deosn't highlight text.

you want use spannablestring this, allows individual parts of string rendered differently in textview.

like so:

    spannablestring str = new spannablestring("highlighted. not highlighted.");     str.setspan(new backgroundcolorspan(color.yellow), 0, 11, 0);     textview.settext(str); 

Comments