Android/webview/html動的変更
提供: 初心者エンジニアの簡易メモ
サンプルコード
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);
