I try to display a TextView with a "chips" style for each word. In other words I would like to have this Splitwise TokenAutoComplete not editable and not autocomplete.
So I have a drawable for my style :
muscle_token_background.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/primary_dark" />
<corners
android:topLeftRadius="5dp"
android:bottomLeftRadius="5dp"
android:topRightRadius="5dp"
android:bottomRightRadius="5dp" />
</shape>
I have my style which use the drawable :
themes.xml
<resources>
<style>
.....
</style>
<style name="textview_chips" parent="@android:style/TextAppearance.Medium">
<item name="android:background">@drawable/muscle_token_background</item>
</style>
</resources>
And the solution I found is to used a SpannableStringBuilder with SyleSpan :
SpannableStringBuilder sb = new SpannableStringBuilder(myString);
int currentCharCount = sb.length();
sb.append(myString.trim());
int nextCharCount = sb.length();
sb.setSpan(new StyleSpan(R.style.textview_chips), currentCharCount, nextCharCount, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
myTextView.setText(sb);
But the TextView only become italic.
I tried with an other TextView in a XML file and the background drawable is well displayed
<TextView
...
style="@style/textview_chips"
... />
So how can I do to apply this style for each word of my TextView ?