forked from Clancey/MonoDroid.Dialog
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathWebContentElement.cs
50 lines (40 loc) · 1.45 KB
/
WebContentElement.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using Android.Content;
using Android.Views;
using Android.Webkit;
namespace Android.Dialog
{
public class WebContentElement : Element
{
public WebContentElement(string url)
: base(string.Empty)
{
Url = Net.Uri.Parse(url);
}
public WebContentElement(Net.Uri uri)
: base(string.Empty)
{
Url = uri;
}
public Net.Uri Url { get; set; }
public String WebContent { get; set; }
public override View GetView(Context context, View convertView, ViewGroup parent)
{
var webView = new WebView(context);
string textColor = ";color:#FFFFFF";
string backgroundColor = "background:#000000;";
if (Url == null)
{
string body = "<html><head><meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no\"/></head><body style=\"-webkit-text-size-adjust:none;{0}margin:10px 15px 15px;font-family:helvetica,arial,sans-serif;font-size:16{1}\">{2}</body></html>";
webView.LoadDataWithBaseURL(string.Empty, string.Format(body, backgroundColor, textColor, WebContent), "text/html", "utf-8", null);
}
else
{
webView.LoadUrl(Url.ToString());
}
webView.SetVerticalScrollbarOverlay(true);
webView.SetMinimumHeight(10);
return webView;
}
}
}