我是靠谱客的博主 友好咖啡豆,这篇文章主要介绍安卓加载图片的路径,Dialog中加载网页(Webview中加载安卓中的图片),现在分享给大家,希望可以做个参考。

 

欢迎安卓开发的小伙伴,当你看到此篇文章,如果对你有帮助,请留下你的爱心的小赞,支持一下呦!!! 

 

 

安卓加载图片的路径

复制代码
1
2
3
4
5
String imageUri = "http://site.com/image.png"; // from Web String imageUri = "file:///mnt/sdcard/image.png"; // from SD card String imageUri = "content://media/external/audio/albumart/13"; //  String imageUri = "assets://image.png"; // from assets String imageUri = "drawable://" + R.drawable.image; // from drawable

安卓加载本地网页 

Dialog中显示网页(Webview中加载安卓本地图片)

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
把网页代码放置在安卓的assets目录下, 通过 String url = "file:///android_asset/xieyi.html";//读取安卓中的网页路径 public class Dialog_web_xieyi extends Dialog { private WebView webView; private String title; public Dialog_web_xieyi(@NonNull Context context, String title) { super(context); this.title = title; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE);//去除标题头 setContentView(R.layout.activity_webview); webView = (WebView) findViewById(R.id.web_xieyis); WebSettings webSettings = webView.getSettings(); //允许webview对文件的操作 webSettings.setAllowUniversalAccessFromFileURLs(true); webSettings.setAllowFileAccess(true); webSettings.setAllowFileAccessFromFileURLs(true); //用于js调用Android webSettings.setJavaScriptEnabled(true); //设置编码方式 webSettings.setDefaultTextEncodingName("utf-8"); webView.setWebChromeClient(new chromClient()); //访问Android assets文件夹内的 String url = "file:///android_asset/xieyi.html"; //访问网页Html webView.loadUrl(url); } private class chromClient extends WebChromeClient { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) { //页面加载完成执行的操作 String path = "file:///android_asset/imag_xieyi.jpg"; String action = "javascript:aa('" + path + "')"; webView.loadUrl(action); } super.onProgressChanged(view, newProgress); } } }

xieyi.html代码 

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <title>Title</title> </head> <body> <img id="img" alt="请查看网络,从新加载" style="width: 100%;height: 100%"/> <script> function aa(path){ alert(path);//web弹窗,在手机端也会弹窗,path为窗体内容 var img=document.getElementById("img"); img.src=path; } </script> </body> </html>

Dialog对话框xml代码 

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <WebView android:id="@+id/web_xieyis" android:layout_width="match_parent" android:layout_height="match_parent" /> </FrameLayout>

 

最后

以上就是友好咖啡豆最近收集整理的关于安卓加载图片的路径,Dialog中加载网页(Webview中加载安卓中的图片)的全部内容,更多相关安卓加载图片内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部