0

I have to set Background image of TextView programatically using s3 image url , how to do it , I am able to access that image in browser using s3 url http://elasticbeanstalk-us-west-2-824932500732.s3.amazonaws.com/Images/android-icon-36x36new.png .

  • Download the image data and then create `Drawable` from the data and set it to `TextView` using `setBackground(Drawable drawable)` – arjun Jan 10 '17 at 16:40
  • But why can't you use `TextView` over `ImageVew`. You can use `FrameLayout` to achieve that – arjun Jan 10 '17 at 16:44
  • I am programatically accessing the s3 url of image from database and using that url I have to set background image of TextView because there is large number of images on s3 – RAJAT SINGH Jan 10 '17 at 16:45
  • I can change it from TextView to ImageView no problem.. if you have any example then please share link . – RAJAT SINGH Jan 10 '17 at 16:46
  • Refer http://stackoverflow.com/a/26976190/2809326 thread. Anyway you have to download the image first. – arjun Jan 10 '17 at 16:48

1 Answers1

0

You can set the TextView (or any View Background) background using Glide Library .

Glide.with(this).load(imageURL).asBitmap().into(new SimpleTarget<Bitmap>() { 
@Override 
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
    Drawable drawable = new BitmapDrawable(resource);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        yourTextView.setBackground(drawable);
    } 
} 
}); 

Glide will get the Image as Bitmap from URL and convert into drawable and use that drawable for background.

Aman Jain
  • 2,975
  • 1
  • 20
  • 35