1

I'm new in Android and trying to let the user to attach picture to the text and when he/she hit send I will send the image to the backend.

I'm trying to do something like hangout or Samsung message application where the chosen image is getting placed inside the EditText, I've been searching for a while but I'm not what what to look for, any one aware of a library that does that? or steps that I need to follow to do this?

Please note that I have everything else working.

  • 1
    Create a RelativeLayout and give it the EditText's background, then Add the EditText and ImageViews inside it. – Abdallah Alaraby Nov 05 '14 at 21:31
  • The images can be added dynamically to a LinearLayout that is inside the RelativeLayout – Abdallah Alaraby Nov 05 '14 at 21:38
  • 1
    possible duplicate of [How can I add an image on EditText](http://stackoverflow.com/questions/3703283/how-can-i-add-an-image-on-edittext) – matiash Nov 05 '14 at 22:18
  • 2
    Possible duplicate of [how to insert image to a editText](http://stackoverflow.com/questions/7818438/how-to-insert-image-to-a-edittext) – bummi Dec 23 '15 at 07:20

2 Answers2

2

If you are talking about small images like emoticons/smileys, i think you can use:

1) setCompoundDrawablesWithIntrinsicBounds

EditText text = (EditText) findViewById(R.id.edtTest);
text.setText("Test");
text.setCompoundDrawablesWithIntrinsicBounds(null, null,
     getResources().getDrawable(R.drawable.myDrawable), null);

Or

2) SpannableString (Able to add more than one drawable dynamically)

SpannableString ss = new SpannableString("abc\n");
Drawable d = img.getDrawable();
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
ss.setSpan(span, 0, 3, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
editT.setText(ss);

According to : How can I add an image on EditText

Otherwise, adding big images to text fields might not be a good idea. Most chat applications separate texts and images while sending as individual EditText and ImageView components.

Community
  • 1
  • 1
0
 <EditText
        style="@style/edit_style"
        android:id="@+id/et_dob"
        android:background="@drawable/selector_edit_back"
        android:layout_width="0dp"
        android:padding="@dimen/common_margin"
        android:inputType="textEmailAddress"
        **android:drawableRight="@drawable/calender"**
        android:imeOptions="actionNext"
        android:singleLine="true"
        android:editable="false"
        android:focusableInTouchMode="false"
        android:hint="Date Of Birth"
        android:textColor="@android:color/white"
        android:textCursorDrawable="@null"
        android:textColorHint="@android:color/white"
        android:layout_height="fill_parent"
        android:layout_weight="9"
        />

see this edit text you can add image in xml also