简体   繁体   中英

Android add shortcut icon from a url instead from drawable resources

I have an app where i am adding shortcut. I want to add shortcut icon image from URL path(images are stored on server and can be change) instead of using Drawable but i don't know how to do that. I tried to find a lot on this community. Any help?

If the term used "shortcut icon" is a view or its descendants such as ImageView , then you can set the image, your application receive from the server by doing this :

add dependency to your app.gradle file :

compile 'com.github.bumptech.glide:glide:3.7.0'

and in the activity you can use this method to set the image to the imageview your app receive from the server :

ImageView imageView = (ImageView) findViewById(R.id.image_view);
Glide.with(imageview.getContext()).load("https://url").error(R.drawable.not_found).centerCrop().into(imageview);

add this in your build.gradle

compile 'com.squareup.picasso:picasso:2.5.2'

now you can load the image using following code

Picaso.with(this).load(urlHere).into(imageView);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM