我有onclick的listview,但是我需要点击每个项目在资源文件夹中打开一个html,我有一些html ..然后需要打开每个项目。
答案 0 :(得分:0)
您可以使用以下代码从您的应用资源文件夹中打开本地html文件
Intent intent=new Intent(this, WebviewActivity.class);
intent.putExtra("url","file:///android_asset/local.html");
startActivity(intent);
<强> WebviewActivity.java 强>
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
public class WebviewActivity extends Activity {
private WebView mWebView;
private String url;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
mWebView = (WebView) findViewById(R.id.webview);
Intent intent=getIntent();
url=intent.getStringExtra("url");
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(url);
}
}
activity_webview.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webviewRootContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webview"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>