MultiAutoCompleteTextView
Google+ アプリでの実装方法と同様に、連絡先バブルを作成しようとしています。以下はスクリーンショットです。
.
DynamicDrawableSpan
テキストのスパンの背景にスパン可能なドローアブルを取得するために、クラスを拡張しようとしました
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;
}
}
私の oval.xml ドローアブルは次のように定義されています。
<?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>
を持つ Activity クラスではMulitAutoCompleteTextView
、バブル スパンを次のように設定します。
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);
ただし、文字列の最初の 6 文字の後ろに楕円形が表示されるのではなく、文字が表示されず、背景に楕円形のドローアブルがありません。
BubbleSpan の getDrawable() メソッドを変更して、シェイプ ドローアブルの代わりに .png を使用する場合:
public Drawable getDrawable() {
Resources res = c.getResources();
Drawable d = res.getDrawable(android.R.drawable.bottom_bar);
d.setBounds(0, 0, 100, 20);
return d;
}
次に、.png が表示されますが、スパンの一部である文字列内の文字は表示されません。スパン内の文字が前景に表示されるようにするにはどうすればよいですか?カスタム形状のドローアブルは背景に表示されますか?
ImageSpan
サブクラス化の代わりにan も使用しようとしましDynamicDrawableSpan
たが、失敗しました。