如果我想制作一个按钮,打开/切换到另一个webview我将如何继续?

时间:2013-09-08 19:43:39

标签: android xml webview

我是编码的新手,我目前有一个webview,在底部显示一个页面和按钮,如;

<Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/webview2"
        android:text="Facebook" />

我如何才能看到Facebook?

1 个答案:

答案 0 :(得分:0)

你的Button需要一个OnClickListener,例如Developer Guide for Button

Button button = (Button) findViewById(R.id.button_send);
button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        // Do something in response to button click
    }
});

在此之后,您还需要布局上的WebView项目,例如Developer Guide for WebView

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

与WebView的按钮相同

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");

你必须完成自己的工作并自己阅读这些内容。关键字是OnClickListener,WebView,WebViewClient(适用于Facebook)。