SoFunction
Updated on 2025-03-02

Android implementation method to add and delete bitmap in EditText

This article describes the method of adding and removing bitmap in EditText on Android. Share it for your reference, as follows:

SpannableString mSpan1 = new SpannableString("1");
/*
* this is add bitmap on edit text
*/
private void displayBitmapOnText(Bitmap thumbnailBitmap) {
if(thumbnailBitmap == null)
return;
    int start = ();
    (new ImageSpan(thumbnailBitmap) , () - 1, (), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//    ();
    if(mEditText != null) {
      Editable et = ();
      (start, mSpan1);
      (et);
      (start + ());
    }
    (10f, 1f);
}
/*
* this is delete bitmap on edit text
* from end to start
*/
private void deleteEditTextSpan() {
    Spanned s = ();
    ImageSpan[] imageSpan = (0, (), ); 
    for (int i =  - 1; i >= 0; i--) {
      if(i ==  - 1) {
        int start = (imageSpan[i]);
        int end = (imageSpan[i]);
        Editable et = ();
        (start, end);
      }
    }
    ();
}

ps:Regarding deletion, I found a lot of people on the Internet who call the soft keyboard directly and then delete it. This is not what I want, this deleteEditTextSpan() is triggered by a custom key

For more information about Android components, please visit the special topic of this site:Summary of the usage of basic Android components

I hope this article will be helpful to everyone's Android programming design.