【问题标题】:Transparent WebView in xamarinxamarin 中的透明 WebView
【发布时间】:2017-07-08 19:06:13
【问题描述】:

我搜索了透明 WebView,但找不到任何问题的答案。

我有这些:

    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>

感谢

编辑:

谢谢寿司宿醉 我使用了您的帮助并编辑了“s”。现在我没有任何问题。谢谢。

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>";

【问题讨论】:

  • 你在用模拟器吗? Webview 不适用于模拟器。尝试一个真实的设备。我也在我的应用上使用 Webviews
  • 是的。我用模拟器。

标签: android xamarin webview xamarin.android background-color


【解决方案1】:

1)不要在布局 axml 中设置背景颜色:

<android.webkit.WebView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/webView" />

2) 设置html中的背景颜色:

<body style='background-color:#00000000;'>

3) 设置WebView在运行时的背景颜色:

WebView.SetBackgroundColor(Color.Transparent);

4) 这应该适用于大多数 API 级别和WebView 版本组合,如果您发现组合不起作用,您还需要打开硬件加速,但通常这只需要旧 API 版本(即2.x/3.x...),我通常不建议关闭加速功能...

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-04
    相关资源
    最近更新 更多