Does Android add more emoticons to one edittext?

I need to add several emoticons to one edittext block. To add one emoticon, I follow this link

How to add more emoticons to one Edittext block? Thanks in advance.

+4
source share
2 answers

You can add as many ImageSpan to Spannable as you want. Just follow the concept outlined by the code you are linking. You probably want to use SpannableStringBuilder .

 Drawable happySmiley = mContext.getResources().getDrawable(R.drawable.happy); happySmiley .setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); Drawable sadSmiley = mContext.getResources().getDrawable(R.drawable.sad); sadSmiley .setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); SpannableStringBuilder builder = new SpannableStringBuilder(); builder.append("Some text [happy_smiley_anchor]"); builder.setSpan(new ImageSpan(happySmiley), builder.length()-"[happy_smiley_anchor]".length(), builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.append(". Some more text [sad_smiley_anchor]"); builder.setSpan(new ImageSpan(sadSmiley), builder.length()-"[sad_smiley_anchor]".length(), builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); edittext.setText(builder); 

Obviously, you can use any anchor text / character you like - it is replaced when you insert ImageSpan . It can even work with an empty char / string, but I did not.

+14
source

You can add as many ImageSpans to Spannable as you want. Just follow the concept outlined by the code you are linking. You probably want to use SpannableStringBuilder .

  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 the code and it works great. I added two images in one text view, you can also add as many images on a textview .

+1
source

Source: https://habr.com/ru/post/1397173/


All Articles