简体   繁体   English

Android从URL而非可绘制资源中添加快捷方式图标

[英]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. 我想从URL路径添加快捷方式图标图像(图像存储在服务器上并且可以更改),而不是使用Drawable,但是我不知道该怎么做。 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 : 如果术语“快捷方式图标”是视图或其后代(例如ImageView ,则可以设置图像,您的应用程序通过执行以下操作从服务器接收:

add dependency to your app.gradle file : 向您的app.gradle文件添加依赖app.gradle

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 = (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 将此添加到您的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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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