WebView inside tab hides tabWidgets

I am having problems with the WebView always filling the full screen and thus closing my tabs. Here is my code for 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 relativization. But the second tab is the action showing the webview and it is displayed but using the entire 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);
 }}

      

+2


a source to share


2 answers


If I had to guess, http://test.server.org:8080/m

does the redirect, in which case it's not yours WebView

that "covers [your] tabs", but rather it's a browser application. WebView

handles redirects and normal clicks by default by launching the Browser app.



+2


a source


Exactly this. I knew about redirects by overriding the shouldOverrideUrlLoading WebViewClient method, but I didn't realize that the URL I was testing was redirecting! lots of.

So, to fix it, here's 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 creating it in onCreate () like this

mWebView.setWebViewClient(new MyWebViewClient());

      

+3


a source







All Articles