I am trying to create contact bubbles in MultiAutoCompleteTextView , similar to how it is implemented in the Google+ application. Below is a screenshot:
.
I tried to extend the DynamicDrawableSpan class to get text stretched against the background of a time lapse
public class BubbleSpan extends DynamicDrawableSpan { private Context c; public BubbleSpan(Context context) { super(); c = context; } @Override public Drawable getDrawable() { Resources res = c.getResources(); Drawable d = res.getDrawable(R.drawable.oval); d.setBounds(0, 0, 100, 20); return d; } }
Where my oval.xml output is defined as follows:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#352765"/> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <corners android:radius="6dp" /> </shape>
In my Activity class, which has a MulitAutoCompleteTextView , I set the bubble range as follows:
final Editable e = tv.getEditableText(); final SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append("some sample text"); sb.setSpan(new BubbleSpan(getApplicationContext()), 0, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); e.append(sb);
However, instead of the oval figure being displayed behind the first six characters in the line, the characters are not visible, and there is no oval selection in the background.
If I change the BDBLED getDrawable () method to use .png instead of the form being extracted:
public Drawable getDrawable() { Resources res = c.getResources(); Drawable d = res.getDrawable(android.R.drawable.bottom_bar); d.setBounds(0, 0, 100, 20); return d; }
Then .png will appear, but the characters in the string that are part of the range will not be displayed. How can I make it so that the characters in the range are displayed in the foreground, meanwhile, in the background, the displayed custom shape is displayed?
I tried also using ImageSpan instead of a subclass of DynamicDrawableSpan , but failed.