android html传值
时间: 2023-07-11 22:22:39 浏览: 40
在 Android 中传递 HTML 值可以使用 Intent。首先,将 HTML 值存储在一个字符串变量中,然后将其传递给另一个 Activity。在接收 Activity 中,使用 WebView 控件显示 HTML 值。
步骤如下:
1. 在发送 Activity 中创建一个 Intent 对象,并使用 Intent 的 putExtra() 方法将 HTML 值作为字符串传递给接收 Activity。
```java
Intent intent = new Intent(SenderActivity.this, ReceiverActivity.class);
intent.putExtra("html", "<h1>This is HTML value</h1>");
startActivity(intent);
```
2. 在接收 Activity 中获取 Intent 对象,并使用 getStringExtra() 方法获取传递的 HTML 值。
```java
Intent intent = getIntent();
String htmlValue = intent.getStringExtra("html");
```
3. 在接收 Activity 中使用 WebView 控件显示 HTML 值。
```java
WebView webView = findViewById(R.id.webview);
webView.loadDataWithBaseURL(null, htmlValue, "text/html", "UTF-8", null);
```
这样,HTML 值将被显示在 WebView 控件中。