use*_*400 7 html android local webview android-studio
我试图在android中的webview中加载html文件的内容.但是,它给了我"网页不可用的错误".如果我尝试谷歌或雅虎等网站,他们的工作.
html文件位于src> main> assests> index.html下
有人可以帮我解决这个问题.谢谢.
以下是我的代码:
setContentView(R.layout.activity_main);
WebView mWebView;
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("file:///android_asset/index.html");
Run Code Online (Sandbox Code Playgroud)
XML文件:
<WebView
android:id="@+id/activity_main_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Run Code Online (Sandbox Code Playgroud)
html文件应放在assets
文件夹中(注意拼写),该文件夹属于项目的根目录.
所以搬家吧
src/main/assests/index.html
Run Code Online (Sandbox Code Playgroud)
至
assets/index.html
Run Code Online (Sandbox Code Playgroud)
在Android Studio项目中使用此文件夹:
/app/src/main/assets/index.html
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20572 次 |
最近记录: |