Android Labels or Bubbles in EditText

前端 未结 8 1706
北恋
北恋 2020-12-02 04:47

\"enterCan someone please point me in the right direction how to do those bubbles or labels in

8条回答
  •  时光说笑
    2020-12-02 05:26

    You can do this by creating a subclass of android.text.style.DynamicDrawableSpan. ImageSpan is an example of this: it replaces a span (range) of text with an image.

    This example will put an a star in an edit field, replacing the text "test". Create an EditText in your layout with the id of "text" and put this in onCreate() (or wherever):

        EditText mText = (EditText) findViewById(R.id.text);
        final Editable e = mText.getEditableText();
        final SpannableStringBuilder sb = new SpannableStringBuilder();
        sb.append("test");
        sb.setSpan(new ImageSpan(this, android.R.drawable.btn_star), 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        e.append(sb);
    

    I didn't see any classes that looked like they could wrap normal text in a drawable, but that could be pretty easily solved by overriding the getDrawable() method and rendering the text yourself.

提交回复
热议问题