【问题标题】:If i wanted to make a button, open/switch to another webview how would i go on about that?如果我想制作一个按钮,打开/切换到另一个 webview 我将如何继续?
【发布时间】:2013-09-08 19:43:39
【问题描述】:

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

<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?

【问题讨论】:

    标签: android xml webview


    【解决方案1】:

    您的 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(for facebook)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-03
      • 1970-01-01
      • 2019-10-20
      相关资源
      最近更新 更多