gpt4 book ai didi

java - 修改android中的html文件

转载 作者:行者123 更新时间:2023-12-01 13:42:35 25 4
gpt4 key购买 nike

我将以下代码放入布局的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 文件。我怎样才能做到这一点?

最佳答案

  1. 从资源中读取 HTML 文件。

  2. 修改应用中的 HTML 数据。

  3. 使用loadData()将修改后的数据加载到WebView (或 loadDataWithBaseURL())而不是 loadUrl()

关于java - 修改android中的html文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20593658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com