White screen is displaying while loading local HTML files in Browser Field?

回眸只為那壹抹淺笑 提交于 2019-12-23 00:52:08

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/15131957/white-screen-is-displaying-while-loading-local-html-files-in-browser-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!