android webview 加载本地文件
来源:互联网 发布:360电脑数据恢复软件 编辑:程序博客网 时间:2024/05/21 10:12
新建一个activity,里面放一个webview
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="webview.fanruitian.cn.webview.MainActivity"> <WebView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/webview" /></android.support.constraint.ConstraintLayout>
开启访问网络权限
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="webview.fanruitian.cn.webview"> <uses-permission android:name="android.permission.INTERNET"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
主要是这句话
<uses-permission android:name="android.permission.INTERNET"/>
注意位置
在app/src/main/目录下建立文件夹asset
在asset目录下建立文件index.html,里面写
<h1>Helo,World</h1>
在oncreate方法里面添加
webView = (WebView) findViewById(R.id.webview); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl("file:///android_asset/index.html"); webView.setWebViewClient(new WebViewClient(){// @Override// public void onPageFinished(WebView view, String url) {// super.onPageFinished(view, url);// } });
测试成功
0 0
- Android webview 加载本地文件
- android webview 加载本地文件
- Android Studio Webview加载assets本地文件
- Android WebView加载本地文件,使用JavaScript定位到指定位置
- webView加载本地文件(zip压缩文件)
- 解决WebView加载本地文件乱码
- 加载本地文件到 WebView 中
- Android WebView + AJAX local files(Android webview ajax加载本地文件)
- Android WebView选择本地文件上传
- Android 5.0WebView选择本地文件
- android加载本地文件数据
- WebView加载页面(URL、HTML、本地文件)
- Android webview调用本地文件选择失败解决
- Android WebView 加载资源
- Android WebView 加载网页
- Android webview加载url
- android webview加载网页
- android webView 不能加载
- Spring事务的传播行为
- 【转载】opencv2 一个窗口显示多幅图片(windows7和bunutu系统)
- 元数据杀人?我们已被网络空间绑架
- 权志龙|instagram粉丝超过1400百万|欧巴特辑
- 外网链接内网:金万维端口映射、路由器设置
- android webview 加载本地文件
- Fragment全解析系列:那些年踩过的坑以及解决方案
- [leetcode] 500. Keyboard Row
- C++编译时遇到“错误:‘SomeClass’没有命名一个类型”
- Windows10 VirtualBox 客户机自启动
- 用手机访问电脑本地Apache下的静态文件方法(坑)
- Eclipse或MyEclipse更换jdk版本
- Redis命令总结
- 第二天过期时间设置问题