【问题标题】:How I can show a webview in a tabwidget?如何在 tabwidget 中显示 webview?
【发布时间】:2012-06-04 09:27:01
【问题描述】:

如何在 tabwidget 中显示 webview? 当我打开选项卡时,webview 在其他新页面中打开,而不在选项卡内容中打开。 问题出在哪里?

代码activity.class:

公共类 layout1i2 扩展 Activity{
按钮按钮 1,按钮 2; WebView webview1, webview2;

      @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.layout1);

          //declarar webvies i botó de tirar enrere       webview1 = (WebView) findViewById(R.id.webview1);       button1 = (Button)

findViewById(R.id.button1); button2 =(按钮) findViewById(R.id.button2);
webview1.loadUrl("http://www.facebook.com"); webview1.setWebChromeClient(new WebChromeClient());

          button1.setOnClickListener(new OnClickListener()        {           @Override           public void onClick(View arg0)              {
          setContentView(R.layout.layout2);
          webview2 = (WebView) findViewById(R.id.webview2);
          button2 = (Button) findViewById(R.id.button2);
          button2.setOnClickListener(new OnClickListener() 
          {
              @Override
              public void onClick(View arg0) 
              {
                  setContentView(R.layout.layout1);
                  webview1 = (WebView) findViewById(R.id.webview1);       
              }
          });             }
});

}

layout2.xml

      <RelativeLayout
          android:id="@+id/Layout2"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" >

          <WebView
              android:id="@+id/webview2"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:autoLink="web"
              android:scrollbars="none"
              android:textColor="@android:color/black" />

          <Button
              android:id="@+id/button2"
              style="?android:attr/buttonStyleSmall"
              android:layout_width="60dp"
              android:layout_height="25dp"
              android:layout_below="@+id/webview2"
              android:layout_alignParentRight="true"
              android:layout_alignParentTop="true"
              android:layout_marginRight="35dp"
              android:layout_marginTop="19dp"
              android:text="Button2"
              android:textSize="14px" />

      </RelativeLayout>

layout1.xml

      <RelativeLayout
          android:id="@+id/Layout1"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" >

          <WebView
              android:id="@+id/webview1"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:autoLink="web"
              android:scrollbars="none"
              android:textColor="@android:color/black" />

          <Button
              android:id="@+id/button1"
              style="?android:attr/buttonStyleSmall"
              android:layout_width="60dp"
              android:layout_height="25dp"
              android:layout_below="@+id/webview2"
              android:layout_alignParentRight="true"
              android:layout_alignParentTop="true"
              android:layout_marginRight="35dp"
              android:layout_marginTop="19dp"
              android:text="Button1"
              android:textSize="14px" />

      </RelativeLayout>

谢谢

【问题讨论】:

    标签: android android-layout tabs webview


    【解决方案1】:

    使用这一行:

    web.setWebViewClient(new WebViewClient());  
    

    【讨论】:

    • 谢谢。我的问题是这个。 jajaja 我忘了写这行。谢谢!
    猜你喜欢
    • 2017-04-28
    • 2013-01-22
    • 2016-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 2012-06-06
    相关资源
    最近更新 更多