2

I would like to insert jpeg images in edittext attached as shown below.

Stackoverflow has recommended this post but the reference projects provided are no longer valid. how to insert jpeg files in edittext android

Will there be any reference projects?

enter image description here

Community
  • 1
  • 1
Antoine Murion
  • 773
  • 1
  • 14
  • 26

3 Answers3

2

try this,

EditText text = (EditText)findViewById(R.id.text);
text.setCompoundDrawables(null,null,getResources().getDrawable(R.drawable.check), null);

That's it.

Ganpat Kaliya
  • 888
  • 2
  • 9
  • 16
1

You can use ImageSpan like this...

buildImageSpan(EditText et){
  SpannableString ss = new SpannableString("anystring");
  Drawable d = getResources().getDrawable(R.drawable.ic_launcher);
  d.setBounds(0,0,d.getIntrinsicWidth(), d.getIntrinsicHeight());
  ImageSpan span = new ImageSpan(d, "anystring", ImageSpan.ALIGN_BASELINE);
  ss.setSpan(span, 0, anystring.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  et.setText(et.getText()+ss);
}
uday
  • 1,348
  • 12
  • 27
  • Does it also work if i want to attach image bitmap from gallery instead of using drawable in the apps? So the same approach will be ok? – Antoine Murion Sep 22 '15 at 09:47
  • refer this answers http://stackoverflow.com/a/5834643/3442067 and http://stackoverflow.com/a/12653027/3442067. you can convert image from storage to Drawable. – uday Sep 22 '15 at 09:51
0

You can set compound drawable top bottom left right using

edittext.setCompoundDrawables(left,top,right, bottom);
Ashish Agrawal
  • 1,977
  • 2
  • 18
  • 32