而在浏览器中加载领域本地HTML文件的白色屏幕显示? [英] White screen is displaying while loading local HTML files in Browser Field?

查看:180
本文介绍了而在浏览器中加载领域本地HTML文件的白色屏幕显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 BrowserField 来显示我的应用程序的一些本地HTML文件。它是正确显示HTML文件。不过,虽然屏幕开始它显示了一些白色画面(背景)。我该如何摆脱这个问题?

我使用的是低于code:

BrowserFieldConfig _bfConfig =新BrowserFieldConfig();
_bfConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
_bfConfig.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED,Boolean.TRUE);
_bfConfig.setProperty(BrowserFieldConfig.USER_AGENT,所有MyApplication 1.0);BrowserField myBrowserField =新BrowserField(_bfConfig);
加(myBrowserField);BrowserFieldRequest要求=新BrowserFieldRequest(地方:///OTPhelp_en.html);
myBrowserField.requestContent(请求);


解决方案

我没有给你一个完美的答案。如果你看看在这个问题,到目前为止,还没有答案已经给出关于如何使 BrowserField 背景透明,这将是的有一个的方式来解决你的问题。

根据如何你的 OTPhelp_en.html 页写的是你有多少控制权的都有,这和频率的变化,这可能是一种解决方法是可以接受的:

如果你的HTML文件中有一个坚实的背景颜色,你知道的颜色是什么(因为它的 HTML内容),那么你可以简单地设置了 BrowserField 背景颜色相匹配。然后,你不会看到任何白色闪光灯呈现的HTML内容之前。事情是这样的:

公共类MyBrowserScreen扩展MainScreen {    //这个假设的HTML文件使用了红色(#FF0000)背景
    私人INT BG_COLOR = Color.RED;    公共MyBrowserScreen(){        //设置屏幕经理的背景
        getMainManager()的setBackground(BackgroundFactory.createSolidBackground(BG_COLOR));        BrowserFieldConfig _bfConfig =新BrowserFieldConfig();
        _bfConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
        _bfConfig.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED,Boolean.TRUE);
        _bfConfig.setProperty(BrowserFieldConfig.USER_AGENT,所有MyApplication 1.0);        BrowserField myBrowserField =新BrowserField(_bfConfig);        //设置浏览器领域的背景相匹配的HTML背景,以及
        //包含屏幕的背景
        _myBrowserField.setBackground(getMainManager()的getBackground());
        加(myBrowserField);        BrowserFieldRequest要求=新BrowserFieldRequest(地方:///OTPhelp_en.html);
        myBrowserField.requestContent(请求);

当然,这种方式硬编码意味着,如果HTML文件改变其背景颜色,你需要改变它在Java code了。

如果你想避免这种情况,你知道HTML文件将始终使用纯色背景颜色,你可以先打开HTML文件作为资源流

的getClass()的getResourceAsStream(/ OTPhelp_en.html)。

,然后解析它,寻找背景色(如<车身的bgcolor = <车身风格=背景色: )。这将至少允许,如果一个简单的背景颜色变化在HTML文件进行浏览器领域寻找合适的。

如果在HTML文件使用渐变背景,或图像的背景下,上述code将要被改变。但是,没有更多的信息,这是我的一个建议的解决方法

I am using BrowserField to display some local HTML files in my application. It is displaying the HTML files properly. But while starting of the screen it is displaying some white screen (background). How can i get rid of this issue?

I am using the below code:

BrowserFieldConfig _bfConfig = new BrowserFieldConfig();
_bfConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
_bfConfig.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE );
_bfConfig.setProperty(BrowserFieldConfig.USER_AGENT, "MyApplication 1.0");

BrowserField myBrowserField = new BrowserField(_bfConfig);
add(myBrowserField);

BrowserFieldRequest request = new BrowserFieldRequest("local:///OTPhelp_en.html");
myBrowserField.requestContent(request);

解决方案

I don't have a perfect answer for you. If you take a look at this question, so far, no answers have been given as to how to make the BrowserField background transparent, which would be one way to solve your problem.

Depending on how your OTPhelp_en.html page is written, how much control over it you have, and how often it changes, this may be a workaround that's acceptable:

If your html file has a solid background color, and you know what that color is (because it's your html content), then you could simply set the BrowserField background color to match. Then, you wouldn't see any white flash before the html content is rendered. Something like this:

public class MyBrowserScreen extends MainScreen {

    // this assumes the html file uses a red (#ff0000) background
    private int BG_COLOR = Color.RED;

    public MyBrowserScreen() {

        // set the screen manager's background
        getMainManager().setBackground(BackgroundFactory.createSolidBackground(BG_COLOR));

        BrowserFieldConfig _bfConfig = new BrowserFieldConfig();
        _bfConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
        _bfConfig.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE );
        _bfConfig.setProperty(BrowserFieldConfig.USER_AGENT, "MyApplication 1.0");

        BrowserField myBrowserField = new BrowserField(_bfConfig);

        // set the browser field background to match the HTML background, and
        //  the containing screen's background
        _myBrowserField.setBackground(getMainManager().getBackground());
        add(myBrowserField);

        BrowserFieldRequest request = new BrowserFieldRequest("local:///OTPhelp_en.html");
        myBrowserField.requestContent(request);

Of course, hardcoding it in this way means that if the HTML file changes its background color, you'll need to change it in the Java code, too.

If you wanted to avoid that, and you knew the HTML file would always use a solid background color, you could first open the html file as a resource stream

getClass().getResourceAsStream("/OTPhelp_en.html");

and then parse it, searching for the background color (e.g. <body bgcolor= or <body style="background-color:). That would at least allow the browser field to look right if a simple background color change is made in the HTML file.

If the HTML file uses a gradient background, or an image background, the above code will have to be changed. But, without more information, that's my suggestion for a workaround.

这篇关于而在浏览器中加载领域本地HTML文件的白色屏幕显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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