facebook twitter hatena line email

Android/webview/コンテンツのない部分を透明に

提供: 初心者エンジニアの簡易メモ
2019年5月13日 (月) 12:11時点におけるAdmin (トーク | 投稿記録)による版 (webviewでコンテンツのない部分を透明に)

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

webviewでコンテンツのない部分を透明に

main_activity.xml

<LinearLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:paddingBottom="20dp"
       android:paddingLeft="20dp"
       android:paddingRight="20dp"
       android:paddingTop="20dp"
       android:background="#ff0000"
       >
       <WebView
           android:id="@+id/webview1"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           />
</LinearLayout>

MainActivity.java

WebView webview = new WebView(this);
webview = (WebView)this.findViewById(R.id.webview1);
webview.setWebViewClient(new WebViewClient());
String html = "<html><body><div style='width:300px;height:400px;text-align:center;vertical-align: middle;display:table-cell;' >" +
                "<img width='200px' src='/hogehoge.jpeg' />" +
                "</div></body></html>";
webview.loadData(html, "text/html", null);
webview.setBackgroundColor(Color.TRANSPARENT);

参考:https://teratail.com/questions/188696