首页 文章

如何在tabwidget中显示webview?

提问于
浏览
0

如何在tabwidget中显示webview?当我打开选项卡时,webview将在其他新页面中打开,而不会在tabcontent中打开 . 问题出在哪儿?

代码activity.class:

public class layout1i2 extends Activity {Button button1,button2; WebView webview1,webview2; @覆盖
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.layout1);

// declarar webviesibotódetirar enrere webview1 =(WebView)findViewById(R.id.webview1); button1 =(按钮)
findViewById(R.id.button1); button2 =(Button)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()
{
@覆盖
public void onClick(查看arg0)
{
的setContentView(R.layout.layout1);
webview1 =(WebView)findViewById(R.id.webview1);
}
}); }

});

}

layout2.xml

<RelativeLayout
android:id =“@ id / Layout2”
机器人:layout_width = “FILL_PARENT”
android:layout_height =“fill_parent”>

<web视图
android:id =“@ id / webview2”
机器人:layout_width = “FILL_PARENT”
机器人:layout_height = “FILL_PARENT”
机器人:自动链接=“网”
机器人:滚动条=“无”
android:textColor =“@ android:color / black”/>

<按钮
android:id =“@ id / button2”
风格= “机器人:ATTR / buttonStyleSmall”
机器人:layout_width = “60dp”
机器人:layout_height = “25dp”
android:layout_below =“@ id / webview2”
机器人:layout_alignParentRight = “真”
机器人:layout_alignParentTop = “真”
机器人:layout_marginRight = “35dp”
机器人:layout_marginTop = “19dp”
机器人:文字= “Button2的”
android:textSize =“14px”/>

</ RelativeLayout的>

layout1.xml

<RelativeLayout
android:id =“@ id / Layout1”
机器人:layout_width = “FILL_PARENT”
android:layout_height =“fill_parent”>

<web视图
android:id =“@ id / webview1”
机器人:layout_width = “FILL_PARENT”
机器人:layout_height = “FILL_PARENT”
机器人:自动链接=“网”
机器人:滚动条=“无”
android:textColor =“@ android:color / black”/>

<按钮
android:id =“@ id / button1”
风格= “机器人:ATTR / buttonStyleSmall”
机器人:layout_width = “60dp”
机器人:layout_height = “25dp”
android:layout_below =“@ id / webview2”
机器人:layout_alignParentRight = “真”
机器人:layout_alignParentTop = “真”
机器人:layout_marginRight = “35dp”
机器人:layout_marginTop = “19dp”
机器人:文字= “Button1的”
android:textSize =“14px”/>

</ RelativeLayout的>

谢谢

1 回答

  • 2

    使用此行:

    web.setWebViewClient(new WebViewClient());
    

相关问题