如何在android中在html页面上显示我的内容
我想在html页面中显示我的数据,我在assest文件夹中创建了一个静态html页面。但我不知道如何以编程方式将我的数据插入该html页面。您的活动中需要有一个。然后将html加载到webview中,下面是一些。从资产加载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"); 但是要以编程方式更改页
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");