Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中在html页面上显示我的内容_Android_Html - Fatal编程技术网

如何在android中在html页面上显示我的内容

如何在android中在html页面上显示我的内容,android,html,Android,Html,我想在html页面中显示我的数据,我在assest文件夹中创建了一个静态html页面。但我不知道如何以编程方式将我的数据插入该html页面。您的活动中需要有一个。然后将html加载到webview中,下面是一些。从资产加载html页面相对简单: WebView webView = (WebView)view.findViewById(R.id.myWebView); webView.loadUrl("file:///android_asset/index.html"); 但是要以编程方式更改页

我想在html页面中显示我的数据,我在assest文件夹中创建了一个静态html页面。但我不知道如何以编程方式将我的数据插入该html页面。

您的活动中需要有一个。然后将html加载到webview中,下面是一些。从资产加载html页面相对简单:

WebView webView = (WebView)view.findViewById(R.id.myWebView);
webView.loadUrl("file:///android_asset/index.html");
但是要以编程方式更改页面内容,您必须首先将资产文件读入字符串,使用字符串替换插入数据,或者使用java.text.MessageFormat

以下是从资产获取inputstream的代码:

AssetManager mgr = this.getAssets();
InputStream is = mgr.open("index.html");
BufferedInputStream in = new BufferedInputStream(is);
// read the contents of the file
填充html字符串后,可以通过编程方式设置webview的内容:

webView.loadData(htmlString, "text/html", "UTF-8");