我将以下代码放入布局的xml文件中。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F0E68C"
android:orientation="vertical" >
<TextView
android:id="@+id/heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="ATTENDANCE STATS"
android:textSize="35dp" />
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:text="click me!"
></Button>
</LinearLayout>
webview 显示一个名为 table.html 的 html 文件。在 Activity 的 java 文件中对此进行了如下处理:
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/table.html");
现在,我想在加载之前从 Activity 的 java 类修改这个 html 文件。我怎样才能做到这一点?
最佳答案
从资源中读取 HTML 文件。
修改应用中的 HTML 数据。
使用
loadData()
将修改后的数据加载到WebView
(或loadDataWithBaseURL()
)而不是loadUrl()
。
关于java - 修改android中的html文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20593658/