MonoDroid的透明的WebView [英] Monodroid Transparent WebView

查看:134
本文介绍了MonoDroid的透明的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重新写一个java Android应用到MonoDroid的,但是我所遇到的问题与我用来显示每个屏幕的内容的WebView的背景透明度。

I'm trying to re-write a java android app into monodroid, however I have come across an issue with the background transparency of the webview that I use to display the contents of each screen.

这code正常工作的Java版本(在绿色背景,黑色文本),但在C#版本,web视图的背景为黑色(绿色背景上的黑色矩形)。

This code works correctly on the java version (Black text on a green background), but in the C# version, the webview's background is black (black rectangle on the green background).

的Java code:

@Override public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    LinearLayout layout = new LinearLayout(getApplicationContext());
    layout.setBackgroundColor(Color.GREEN);
    WebView webView = new WebView(getApplicationContext());
    layout.addView(webView);
    setContentView(layout);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setBackgroundColor(Color.TRANSPARENT);

    webView.loadData("<html><body style='background-color: transparent;'>" + 
                     "Some text...</body></html>", "text/html", "UTF-8");
}

C#code:

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);

    var layout = new LinearLayout(ApplicationContext);
    layout.SetBackgroundColor(Color.Green);
    var webView = new WebView(ApplicationContext);
    layout.AddView(webView);
    SetContentView(layout);
    webView.Settings.JavaScriptEnabled = true;
    webView.SetBackgroundColor(Android.Resource.Color.Transparent);

    webView.LoadData("<html><body style='background-color: transparent;'>" +
                        "Some text...</body></html>", "text/html", "UTF-8");
}

我知道有类似的问题,人们有在哪里,但他们通常都认为Java版本无法正常工作。我的C#是有问题的,但...

I know that there are similar issues that people where having, but they usually were that java version not working. My C# is having the problems though...

我使用的是默认的项目模板在这两种情况下。

I am using the default project template in both cases.

我是什么忘记了或者不这样做?

What am I forgetting or not doing?

推荐答案

它看起来像Android.Resource.Color.Transparent值是错误的。

It looks like the value for Android.Resource.Color.Transparent is wrong.

尝试:

webView.SetBackgroundColor(0);

webView.SetBackgroundColor(new Color (0, 0, 0, 0));

更新:

其实,这个问题是您正在使用,而不是Android.Graphics.Color.Transparent Android.Resource.Color.Transparent。资源是资源ID,而不是一种颜色。

Actually, the issue is you are using Android.Resource.Color.Transparent instead of Android.Graphics.Color.Transparent. Resource is a resource id, not a color.

说了这么多,Android.Graphics.Color.Transparent也不管用。它是连接$ C $光盘作为0xFFFFFF00这显然不是透明的为Android。我已经将它切换到00000000下一个版本。

Having said that, Android.Graphics.Color.Transparent doesn't work either. It's encoded as 0xFFFFFF00 which apparently isn't transparent for Android. I've switched it to 0x00000000 for the next release.

在code以上将用于现在的工作。

The code above will work for now.

这篇关于MonoDroid的透明的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆