xamarin中的透明WebView [英] Transparent WebView in xamarin
问题描述
我搜索了透明WebView,但是找不到我的问题的答案.
I searched Transparent WebView but I could not find any answer for my problem.
我有这些:
string str = "Hello. How are you? I am fine.";
String s = "<html><head><style type='text/css'>body {"
+ "text-align: justify;}</style></head><body dir = rtl>"
+str
+ "</body></html>";
webview.LoadDataWithBaseURL("", s, "text/html", "utf-8", null);
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/webView1"
android:background="@android:color/transparent" />
</LinearLayout>
谢谢
谢谢SushiHangover 我使用了您的帮助,并编辑了"s".现在我没有任何问题.谢谢.
Thank you SushiHangover I used your help and I edited "s". Now I do not have any problem. Thank you.
string str = "Hello. How are you? I am fine.";
String s = "<html><head><style type='text/css'>body {background-color:#00000000;"
+ "text-align: justify;}</style></head><body dir = rtl>"
+"<font style='opacity:0.79'>"
+ "<font color='white'>" + str + "</font>"
+ "</body></html>";
推荐答案
1)不要不在布局axml中设置背景颜色:
1) Do not set a background color in the layout axml:
<android.webkit.WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView" />
2)在html中设置背景颜色:
2) Set the background color in html:
<body style='background-color:#00000000;'>
3)在运行时设置WebView
的背景色:
3) Set the background color of the WebView
at runtime:
WebView.SetBackgroundColor(Color.Transparent);
4)这应该适用于大多数API级别和WebView
版本组合,如果您发现不起作用的组合,则还需要启用硬件加速功能,但是通常只有旧的API版本才需要(例如2.x/3.x ...),通常我不建议您关闭加速...
4) This should work on most API level and WebView
version combinations, if you find a combination that does not work you will also need to turn of hardware acceleration, but typically this is only needed for old API version (i.e. 2.x/3.x...) and I would typically not recommend in turning acceleration off...
WebView.SetLayerType(LayerType.Software, null);
示例:
string htmlContent = "Hello. How are you? I am fine.";
string htmlString = @"
<html>
<head>StackOverFlow</head>
<body style='background-color:#00000000;'>
<div>
" + htmlContent + @"
</div>
</body>
</html>
";
webview.SetBackgroundColor(Color.Transparent);
webview.LoadDataWithBaseURL("", htmlString, "text/html", "UTF-8", null);
这篇关于xamarin中的透明WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!