views:

449

answers:

2

I'm having trouble with a WebView always filling the full screen and thus covering my tabs. Here is my code for the tabhost..

    public class tabNZBMobile extends TabActivity {
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

  Resources res = getResources(); // Resource object to get Drawables
  TabHost tabHost = getTabHost();  // The activity TabHost
  TabHost.TabSpec spec;  // Reusable TabSpec for each tab
  Intent intent;  // Reusable Intent for each tab

  // Create an Intent to launch an Activity for the tab (to be reused)
  intent = new Intent().setClass(this, NewzbinMobile.class);

  // Initialize a TabSpec for each tab and add it to the TabHost
  spec = tabHost.newTabSpec("search").setIndicator("Search",
    res.getDrawable(R.drawable.ic_tab_search))
    .setContent(intent);
  tabHost.addTab(spec);

  // Do the same for the other tabs
  intent = new Intent().setClass(this, sabnzbWeb.class);
  spec = tabHost.newTabSpec("sabnzbweb").setIndicator("SabNZBd",
    res.getDrawable(R.drawable.ic_tab_sabnzbweb))
    .setContent(intent);
  tabHost.addTab(spec);

  tabHost.setCurrentTabByTag("search");
 }}

My first tab (NewzbinMobile.class) displays correctly, it's just a relativelayout. But my second tab is an activity showing a webview and it is showing, but using the whole screen, covering my tabs. Here is the code for my second tab.

    public class sabnzbWeb extends Activity {
 WebView mWebView;
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  String sabNZBurl = new String("http://test.server.org:8080/m");

  mWebView = new WebView(this);
  mWebView.getSettings().setJavaScriptEnabled(true);
  setContentView(mWebView);
  mWebView.loadUrl(sabNZBurl);
 }}
A: 

If I had to guess, http://test.server.org:8080/m does a redirect, in which case it's not your WebView that is "covering [your] tabs", but rather it is the Browser application. WebView by default handles redirects, and regular clicks, by launching the Browser application.

CommonsWare
A: 

That is exactly it. I knew about handling redirects by overriding the shouldOverrideUrlLoading method of WebViewClient, but I didn't realize the url I was testing with was redirecting! ty very much.

So to fix, here is what I did..

final class MyWebViewClient extends WebViewClient {
    @Override
    // Show in WebView instead of Browser
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        view.loadUrl(url);
        return true;
    }
}

And then add MyWebViewClient to my WebView right after I create it in onCreate() like this

mWebView.setWebViewClient(new MyWebViewClient());
brockoli