Android add more smileys in one edittext?

后端 未结 2 1875
旧时难觅i
旧时难觅i 2020-12-09 23:49

I need to add more than one smileys in a single edittext box. For add a single smiley I follow this link

How to add more smileys in a single Edittext box? Thanks in

2条回答
  •  暖寄归人
    2020-12-10 00:11

    You can add as many ImageSpans to a Spannable as you like. Just follow the concept laid out by the code you're linking. You probably want to use a SpannableStringBuilder too.

    SpannableStringBuilder ssb = new SpannableStringBuilder("Some Text"); 
    Bitmap image1 = BitmapFactory.decodeResource( getResources(), R.drawable.yourimage1 ); 
    Bitmap image2 = BitmapFactory.decodeResource( getResources(), R.drawable.yourimage1 ); ssb.setSpan( new ImageSpan( image1 ), 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE );
    ssb.setSpan( new ImageSpan( image2 ), 2,3, Spannable.SPAN_INCLUSIVE_INCLUSIVE ); 
    deleteButton.setText( ssb, BufferType.SPANNABLE );
    

    I tried above code and it works fine. I added two image span in one text view, likewise you can add as many image span to textview.

提交回复
热议问题