android把图片url转为drawable
本文最后更新于 2025年4月21日 上午
1 | InputStream in = (InputStream) new URL("http://xxx.jpg").openStream(); |
以下示例给linearlayout设置网络图片为背景
1 | linear=(LinearLayout)findViewById(R.id.linear); |
注意,http请求需要在子线程中完成,UI更新需要在主线程中完成
android9.0以上版本中允许http请求需要在AndroidManifest.xml中的application标签中添加
android:usesCleartextTraffic=”true”
android把图片url转为drawable
http://example.com/2021/01/18/android把图片url转为drawable/