facebook twitter hatena line email

「Android/webview/html動的変更」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(assetsにおいたindex.htmlを一部変更するサンプルコード)
(サンプルコード)
 
行1: 行1:
 
==サンプルコード==
 
==サンプルコード==
src/main/assets/index.htmlにhtmlソースを置く
 
 
  String html = "<<nowiki />html><<nowiki />head><<nowiki />head><<nowiki />body>test</body></html>";
 
  String html = "<<nowiki />html><<nowiki />head><<nowiki />head><<nowiki />body>test</body></html>";
 
  webview.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "UTF-8", null);
 
  webview.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "UTF-8", null);

2019年6月28日 (金) 13:16時点における最新版

サンプルコード

String html = "<html><head><head><body>test</body></html>";
webview.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "UTF-8", null);

assetsにおいたindex.htmlを一部変更するサンプルコード

src/main/assets/index.htmlに置く

String html = "";
try {
           InputStream is = getAssets().open("index.html");
           int size = is.available();
           byte[] buffer = new byte[size];
           is.read(buffer);
           is.close();
           html = new String(buffer);
} catch (IOException e) {throw new RuntimeException(e);}
html = html.replace("{hogehoge}", "hogehoge");
webview.loadDataWithBaseURL("ttp://hoge.example.com", html, "text/html", "UTF-8", null);