Matt
Matt

Reputation: 77

Webbrowser blank on android

I'm using a Webbroswer component to display some HTML file stored on the device. I was finally able to display it properly. But I've a remaining problem on android : the Webbrowser is displayed but it's filled with blank.

But if I click on it, it then display the correct content!

I've try to use some revalidate(), forceRevalidate(), requestFocus() calls and thinks like that but I couldn't solve the problem. Any idea?

Upvotes: 1

Views: 78

Answers (3)

Shai Almog
Shai Almog

Reputation: 52760

The WebBrowser/BrowserComponent need to be in the center of a border layout in a Form or in a layout similar to the one described here: Using two WebBrowsers on codename one (layout management)

The reason for this is simple, the HTML is loaded asynchronously by the native browser rendering engine. While it's loading the browser has no "preferred size" hence it will get sized to 0. Notice that even if your HTML is local to the device this will be running in an asynchronous thread!

Update:

Trying to reproduce your issue I did this which worked fine on my OPO device.

    Form hi = new Form("Tab Test", new BorderLayout());
    Tabs tb = new Tabs();
    hi.add(BorderLayout.CENTER, tb);
    BrowserComponent bc = new BrowserComponent();
    bc.setURL("https://www.codenameone.com/");
    tb.addTab("First", bc);
    tb.addTab("Second", new Label("Dummy"));
    hi.show();

Screenshot from OPO

Upvotes: 0

Matt
Matt

Reputation: 77

Here is the code I use :

WebBrowser wb = new WebBrowser();

if( wb.getInternal() instanceof BrowserComponent )
{
    BrowserComponent bc = (BrowserComponent) wb.getInternal();
    bc.setPinchToZoomEnabled( true );
}

wb.setPage( textToDisplay, "" );

findModuleDetailsContainer( currentContainer ).addComponent( BorderLayout.CENTER, wb );

Form currentForm = Display.getInstance().getCurrent();
currentForm.forceRevalidate();

And then I've tried to add some revalidate() on webbrowser and its container, but nothing work:

wb.revalidate();
findModuleDetailsContainer( currentContainer ).revalidate();

Upvotes: 1

tizbn
tizbn

Reputation: 1907

there is some problem in webbrowser's style so changes its bg color to other color as shown in below codes

    webbrowser.getAllStyle().setBgColor(0x55ff0000);
    webbrowser.getUnselectedStyle().setBgColor(0x5500ff00);

and when the content is displayed chanage its bg color as per you needs.

Upvotes: 0

Related Questions