how can I set drawable background just to a number string into another string in android?

1.2k views Asked by At

is there any way to set background (xml circular drawable) to a number or any string between another string ?

I have (for example) this text in the textView (copied from stackoverflow):

You are setting the text on bookDisp(I guess that this is the TextView) and then instead of using the text from that 54 TextView you do a compare between the TextView object(bookDisp) and the test String that will fail. You'll probably want to do:

my xml circular drawable

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<size android:width="48dp" android:height="48dp"/>
    <corners android:radius="24dp" />
    <solid android:color="#00838F"/>
</shape>

i want to set circular drawable as a background just for the 54 number in that TextView.

can I use Spannable class for that ? if yes, how?

Thanks

1

There are 1 answers

0
7heaven On

I wrote a library to draw any drawable as background of characters in TextView.you can even customize the selection style for EditText.the address is md2tv

here is how it looks like: enter image description here

with customize selection style:

enter image description here