【问题标题】:WebView inside Tab hiding the tabWidgetsTab内的WebView隐藏了tabWidgets
【发布时间】:2010-04-26 23:45:22
【问题描述】:

WebView 总是填满全屏并因此覆盖我的标签时遇到问题。这是我的标签主机代码..

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

我的第一个选项卡 (NewzbinMobile.class) 显示正确,它只是一个相对布局。但我的第二个选项卡是一个显示 web 视图的活动,它正在显示,但使用整个屏幕,覆盖我的选项卡。这是我的第二个标签的代码。

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

【问题讨论】:

    标签: android webview android-tabhost


    【解决方案1】:

    就是这样。我知道通过覆盖 WebViewClient 的 shouldOverrideUrlLoading 方法来处理重定向,但我没有意识到我正在测试的 url 正在重定向!非常喜欢。

    所以要修复,这就是我所做的......

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

    然后像这样在 onCreate() 中创建 MyWebViewClient 到我的 WebView 中

    mWebView.setWebViewClient(new MyWebViewClient());
    

    【讨论】:

      【解决方案2】:

      如果我不得不猜测,http://test.server.org:8080/m 会进行重定向,在这种情况下,不是您的 WebView“覆盖 [您的] 标签”,而是浏览器应用程序。 WebView 默认情况下通过启动浏览器应用程序来处理重定向和常规点击。

      【讨论】:

        猜你喜欢
        • 2019-01-24
        • 1970-01-01
        • 1970-01-01
        • 2011-08-17
        • 2010-10-18
        • 2012-08-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多